How to AJAX upload image/jpeg content?

I’m dealing with a custom API that requires image uploads as image/jpeg, that gives a PHP example that uses a CURL command.

curl –X POST --upload ./vehicle.jpg –H 'Content-Type: image/jpeg'

I’m attempting to research how to achieve this as an AJAX post, but am only finding examples with a content-type of multipart/form-data.

Does anyone have reference material for how to achieve an AJAX upload using a content-type of image/jpeg ?

Hey Paul,

I’m not sure this is even possible. I just spent a while messing about with Ajax uploads using the FormData interface, hoping one could set the content type manually to ‘image/jpeg’ and still have things work. Unfortunately, doing this just resulted in an empty payload being sent to the server. This is probably not news to you.

The only other thing that occurred to me was that you could stick some kind of PHP proxy between your JS script and the API and then have it intercept the Ajax call and translate it into something the API can deal with. No idea how practical that is in your case.

Nonetheless, it’s be interesting to hear how you got on with this. Could you share the API in question?

1 Like

It’s a custom api developed by a local company to act as an interface to create and manage trademe postings,
.

I’ve told my client that further progress cannot be achieved until their server supports the curl interface.

Thanks for the investigation.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.