Opened 9 years ago
Last modified 23 months ago
#32318 new defect (bug)
Upload fails, wp_insert_attachment returned 0
Reported by: | programmin | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 4.1.5 |
Component: | Upload | Keywords: | close dev-feedback |
Focuses: | administration | Cc: |
Description
One specific mp3 file was failing to attach, and it seems wp_insert_attachment is breaking with 0 returned, breaking update-attachment-metadata:
wp-admin/includes/media.php, line 360:
// Save the data $id = wp_insert_attachment($attachment, $file, $post_id); if ( !is_wp_error($id) ) { wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); }
id = 0, caused by these lines in wp-includes/post.php, around line 3351:
if ( false === $wpdb->insert( $wpdb->posts, $data ) ) { if ( $wp_error ) { return new WP_Error('db_insert_error', __('Could not insert post into the database'), $wpdb->last_error); } else { return 0; } }
In this case the documentation is wrong, it didn't return the post id.
Attachments (1)
Change History (13)
#2
@
9 years ago
I'm seeing the same behavior in Wordpress 4.3. It adds it to the server, but fails before adding it to media library.
#3
@
9 years ago
Perhaps I should rephrase this bug - I have to wonder if there is any wordpress install that does not have problems with that mp3, and many similar ones. On sites that have no problem uploading various file types and mp3s, this type of file fails, always. So, is there some option that I happen to have enabled, or some mp3-tag library that happened to be out of date on all systems I tried on?
This is happening on 4.3.2 preview as well.
#4
@
9 years ago
If you add a var_dump($data) before that return 0 you will see that on files this fails on there's weird metadata like "Genre: ÿþ." Is this a misconfiguration of id3 reader you are using?
At the very least can have an error message that says this file has unrecognized metadata and wasn't saved to the database, and remove the file from the server since it didn't get added to the media library?
#5
@
9 years ago
This is still happening in Wordpress 4.4 beta, by the way - some mp3s upload fine, the one attached above, and many similar ones, will never appear in the media modal after uploading, "An error occurred in the upload. Please try again later."
This is happening the same on two different sites with two different themes, running 4.4 beta.
#6
@
9 years ago
FYI still happening in WP 4.4.1. Is there anything further I should do to track down the problem?
#7
@
9 years ago
- Focuses administration added
- Keywords close added
It appears the mp3 file you uploaded contains invalid headers. While it may play on some devices, by definition of spec it is not a valid mp3 file (similar to how an HTML document that can render in a browser doesn't necessarily have to pass the w3c HTML validity checker). Attempted validation of the file's format fails on several open source mp3 file validity checkers, such as Checkmate MP3 checker.
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
9 years ago
#9
@
9 years ago
Thank you, I hadn't heard about that program for checking mp3 files! Even so it seems really bad that mp3 files could be uploaded successfully, then just fail with an error when the file is still taking space on the server. If user does this repeatedly for large files it could be very bad. Can't this be handled better in cases like this?
#10
@
5 years ago
- Keywords dev-feedback added
@joemcgill @mikeschroder Are you aware of any way this can be handled a bit better?
#11
@
5 years ago
It looks like the documentation for wp_insert_attachment()
have since been updated to account for the case of 0
being returned.
We could attempt to have a garbage collection job for files that are successfully uploaded, but fail to be inserted to the database, maybe? I agree that this is currently not ideal.
Any ideas? IIRC this behavior has happened before with another specific file not able to upload to a Wordpress blog.