Support » Developing with WordPress » Using the media API

  • Hi,

    I am trying to upload a base64 encoded string with the API. Either the documentation is incomplete (http://v2.wp-api.org/reference/media/) or I missed something as to where the content is supposed to go. I came across this issue report on Github but that didn’t help me further. https://github.com/WP-API/WP-API/issues/1768

    I am making a POST request, in which I get a 201 response, which should mean it was created. And using the filemanager/browser I can see that there is something created but the image is broken/not working. Below is a sample of my JS code.

    $.ajax({
                                url: wpApiSettings.root + wpApiSettings.versionString + 'media',
                                method: 'POST',
                                beforeSend: function (xhr) {
                                    xhr.setRequestHeader('X-WP-Nonce', wpApiSettings.nonce);
                                    xhr.setRequestHeader('Content-Type', 'image/jpeg');
                                    xhr.setRequestHeader('Content-Disposition', 'attachment;filename=image_1.jpeg');
                                },
                                data: {
                                    base64encodedjpegimagestring
                                }
                            });
    • This topic was modified 4 months, 1 week ago by  tuim. Reason: Added clarification

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • You haven’t actually described the problem you’re having. What’s the request you’re trying and what’s the response you get?

    You are right, I have a added a clarification and some code I am using.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.