[wp-trac] [WordPress Trac] #41774: REST-API: Media endpoint (POST): Unable to upload files

WordPress Trac noreply at wordpress.org
Fri Sep 1 07:55:09 UTC 2017


#41774: REST-API: Media endpoint (POST): Unable to upload files
--------------------------+-----------------------------
 Reporter:  tiger42       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.8.1
 Severity:  normal        |   Keywords:
  Focuses:  rest-api      |
--------------------------+-----------------------------
 I have found a possible bug in the file "'''wp-includes/rest-api/endpoints
 /class-wp-rest-attachments-controller.php'''", which prevents me from
 uploading media files via the "media" REST endpoint. Every time I try to
 upload a file, I get the following response:

 {{{
 {
    "code": "rest_upload_unknown_error",
    "message": "File is empty. Please upload something more substantial.
 This error could also be caused by uploads being disabled in your php.ini
 or by post_max_size being defined as smaller than upload_max_filesize in
 php.ini.",
    "data": {"status": 500}
 }
 }}}

 The problem seems to be in line 719:
 {{{#!php
 $file = wp_handle_upload( $files['file'], $overrides );
 }}}
 After some debugging, I have found out that the array in the $files
 variable does not have the format that seems to be expected. After
 changing the line to the following code, the file upload works for me
 without problems:
 {{{#!php
 $file = reset( $files );
 $file = wp_handle_upload( $file, $overrides );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/41774>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list