Reputation: 433
I have a REST API at the backend (built on flask). Now i need to send/upload an image at the client side and return JSON in response. So that would be GET request with Image data. Since i'm new to the client side interface, what could be the simplest way to send an image data to the server? There just needs to be an upload image button to get the JSON in response. I've read answers to base64 encode the image file and send it with no simple example on how it should be done. Many have suggested Knockout or Angular but i don't have much time to go through them. Please suggest if there's a simpler way as well.
Upvotes: 2
Views: 5300
Reputation: 6570
In REST, GET should return values, not change data on the server. All the request information is sent via the URL, as well, which may produce problems if it's too long.
So use PUT or POST and send the data:
$.ajax({
url:'the service url',
method: 'PUT',
data: { image: base64ImageString }
});
Additional info from a very similar question [hint!] here: Jquery Ajax - post huge string value
Upvotes: 1