I’d like to build a simple HTML page that includes JavaScript to perform a form POST with image data that is embedded in the HTML vs a file off disk.
I’ve looked at this post which would work with regular form data but I’m stumped on the image data.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
** UPDATE ** Feb. 2014 **
New and improved version available as a jQuery plugin:
https://github.com/CoeJoder/jquery.image.blob
Usage:
Requirements
Thus the browser requirements are:
Note: The images must be of the same-origin as your JavaScript, or else the browser security policy will prevent calls to
canvas.toDataURL()(for more details, see this SO question: Why does canvas.toDataURL() throw a security exception?). A proxy server can be used to circumvent this limitation via response header injection, as described in the answers to that post.Here is a jsfiddle of the below code. It should throw an error message, because it’s not submitting to a real URL (‘/some/url’). Use firebug or a similar tool to inspect the request data and verify that the image is serialized as form data (click “Run” after the page loads):
Example Markup
The JavaScript
References
SO: ‘Convert DataURI to File and append to FormData