• onethreethreeseven

    (@onethreethreeseven)


    [ Moved to the Developing with WordPress sub-forum. ]

    Hi. Im trying to upload png image via REST Api. To be more precise Im using Python and Requests library (code below).
    I use “Content-Disposition”: “attachment; filename=image.png”, and set Content-Type to “image/png” or “multipart/form-data” but then I get:

    {"code":"rest_upload_sideload_error","message":"Sorry, this file type is not permitted for security reasons.","data":{"status":500}}'

    requests.post(url=media_url, headers=headers, auth=auth, files={
    'file': open(filename, 'rb')})

    Have you got any ideas? I don’t see any solutions in docs.

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It may be related to Trac #39952. There is an unresolved bug related to upload MIME type validation. Most focus has been on non-image files, and #39552 relates specifically to SVG files, but there may be broader application. Regardless, there is something in _wp_handle_sideload() that is rejecting your file for some reason. If you can identify what exactly is causing the rejection through debugging techniques, you should be able to correct the situation by either correcting the files or by installing a workaround through one of the provided hooks.

Viewing 1 replies (of 1 total)
  • The topic ‘Uploading image via REST Api v2’ is closed to new replies.