Ticket #9233 (closed defect (bug): fixed)
Updating an uploaded media file via AtomPub PUT fails
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 2.7.2 |
| Component: | AtomPub | Version: | 2.7.1 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | josephscott, westi |
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
Change History
comment:1
follow-up:
↓ 2
josephscott — 3 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()
comment:3
josephscott — 3 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.
comment:4
automattor — 3 years ago
- Status changed from new to closed
- Resolution set to fixed
- Status changed from closed to reopened
- Resolution fixed deleted
Re open for 2.7.2


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.