• Resolved Ram Shengale

    (@ramshengale)


    I have enabled the Remove Local Media option and that’s deleting all media after offloading to DigitalOcean except for PDF and CSV files.

    How to fix this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Delicious Brains Support

    (@dbisupport)

    Hi Ram,

    WP Offload Media Support Team here. Thanks for reaching out with your query, we would be happy to assist!

    May we know if those files are a) in the Media Library, and b) offloaded to your bucket? WP Offload Media Lite only offloads files that have records in your Media Library.

    If the PDF and CSV files don’t exist in your Media Library, they are not offloaded. If they are not offloaded, they won’t be removed from your server.

    Looking forward to your response!

    Thread Starter Ram Shengale

    (@ramshengale)

    a) They’re in Media Library
    b) They were offloaded to the bucket

    Everything else is working except deletion of PDF and CSV files. Files of other formats are getting deleted.

    Thread Starter Ram Shengale

    (@ramshengale)

    Update:
    Note that we’re uploading the files using code (using default WordPress functions) and some processing happens for these PDF and CSV files after upload.

    I think I read somewhere in your docs that you skip deleting the files if one of the hooks is called. I’m not able to find that documentation now.

    Is there a way to delay the deletion of those files after that?

    Plugin Support Delicious Brains Support

    (@dbisupport)

    Hi @ramshengale,

    Thanks for providing further information. Currently, there’s no way to schedule/delay the removal of files.

    Could you please confirm if the update attachment metadata was triggered after the files were processed/modified? It’s possible that the files weren’t removed since that function wasn’t triggered again.

    WP Offload Media uses the wp_update_attachment_metadata filter to recognize that something has changed in the Media Library item’s makeup, and uses this as the trigger to offload any files that haven’t been already.

    More info here – https://deliciousbrains.com/wp-offload-media/doc/developer-guide/#automatic-offload-hooks

    Otherwise, we suggest trying to delay the offload until you’re done modifying/processing the file.

    We previously ran into an issue wherein a customer was using a plugin called TinyPNG. Our plugin offloaded the file before the optimization was finished which caused some issues. It may be similar to what you’re encountering right now.

    A colleague of mine created a snippet for TinyPNG to fix this wherein it delays the offload until TinyPNG finishes its optimization. You may be able to edit that to accommodate your own code:

    function pre_update_attachment_metadata( $abort, $data, $post_id, $old_as3cf_item ) {
    
    // prevent offload on upload. default value of $abort is false
    
    $tinypng = get_post_meta( $post_id, 'tiny_compress_images', true ); // TinyPNG creates this metadata for the attachment
    
    if ( ! $tinypng ) {
    
    // TinyPNG hasn't finished compressing this yet, abort for now. This will be called again once TinyPNG finishes and this will be bypassed then
    
    return true; // abort
    
    }
    
    // if we're here, then TinyPNG has finished optimizing images, images will be offloaded now
    
    return $abort;
    
    }
    
    add_filter( 'as3cf_pre_update_attachment_metadata', 'pre_update_attachment_metadata', 10, 4 );

    You can add this to your custom theme’s functions.php file or in a custom plugin.

    Since that will delay the offload, the removal of the files will also be delayed which may be able to fix the issue you’re having.

    We look forward to hearing back!

    Thread Starter Ram Shengale

    (@ramshengale)

    There was some bug in our code which was causing this issue. We’ve fixed that now and everything seems to be working well.

    Sorry for the trouble and thank you for your support.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PDF and CSV files not getting removed from local’ is closed to new replies.