#9233 closed defect (bug) (fixed)
Updating an uploaded media file via AtomPub PUT fails
Reported by: | josephscott | Owned by: | josephscott |
---|---|---|---|
Milestone: | 2.7.2 | Priority: | normal |
Severity: | normal | Version: | 2.7.1 |
Component: | AtomPub | Keywords: | has-patch |
Focuses: | Cc: |
Description
Tim Armes reported on the wp-xmlrpc email list that attempts to update media uploads via AtomPub PUT are failing:
Finally, I've discovered a more serious problem. It's not possible to PUT an updated image file. Wordpress returns 200 to say that it's all worked, but in reality it hasn't. I tracked it down to this code in the put_file function: $location = get_post_meta($entry['ID'], '_wp_attached_file', true); $filetype = wp_check_filetype($location); if(!isset($location) || 'attachment' != $entry['post_type'] || empty($filetype['ext'])) $this->internal_error(__('Error ocurred while accessing post metadata for file location.')); $fp = fopen("php://input", "rb"); $localfp = fopen($location, "w+"); log_app("tim", $location); while(!feof($fp)) { fwrite($localfp,fread($fp, 4096)); } fclose($fp); fclose($localfp); When I PUT to ..../attachement/file/ID the code tries to locate the physical file and overwrite it. The problem is that $location actually gets the path relative to the uploads folder, so it contains something like 2009/02/myfile.jpg
I've included a patch to fix the location problem by looking up the proper upload dir via wp_upload_dir(). With the patch I've confirmed that updates to an uploaded file via AtomPub PUT work.
I noticed another problem though, it only updates the original file, not the generated versions or the meta data. This is particularly bad if the updated image is a different size. I tried calling wp_generate_attachment_metadata() after updating the image, but it didn't update the generated images or the meta data about the image.
Attachments (1)
Change History (7)
#2
in reply to:
↑ 1
@
16 years ago
- Cc westi added
Replying to josephscott:
Updated the diff to correctly call wp_generate_attachment_metadata() so that new generated images are done and meta data gets updated. Kudos to tellyworth for explaining how that worked.
Is this the correct diff - it doesn't add a call to wp_generate_attachment_metadata()
#3
@
16 years ago
Oops, must have botched the previous diff update. I've replaced it again and confirmed that it has the corrected wp_generate_attachment_metadata() call in it.
Updated the diff to correctly call wp_generate_attachment_metadata() so that new generated images are done and meta data gets updated. Kudos to tellyworth for explaining how that worked.