I need to convert a dataURL to a File object in Javascript in order to send it over using AJAX. Is it possible? If yes, please tell me how.
Share
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.
If you need to send it over ajax, then there’s no need to use a
Fileobject, onlyBlobandFormDataobjects are needed.As I sidenote, why don’t you just send the base64 string to the server over ajax and convert it to binary server-side, using PHP’s
base64_decodefor example? Anyway, the standard-compliant code from this answer works in Chrome 13 and WebKit nightlies:Then just append the blob to a new FormData object and post it to your server using ajax: