1

is it possible to have an image exported via canvas (canvas.toDataURL("image/png")) and bound to <input type="file" /> upload control programmatically without the usage of server side technology (so, only javascript)?

So basically, my client has a <form> and among other fields he would like to have an editable image field which would be added to the file upload HTML control on POST. I can't do it any other way since the existing <form> is third party which means I can't modify the server side logic and the client insist on keeping that third party <form>.

So, I have a specific wish from a client and I rally don't know if this is possible. Any tips/pointers/help would be appreciated. Thanks!

EDIT: probably should have mentioned that the solution must work cross-browser up to an including IE7

asked Jan 16, 2013 at 14:11

1 Answer 1

2

Probably you can achieve it using FormData. You need to covert the canvas image to binary using BlobBuilder. With FormData you can:

var dataURL = canvas.toDataURL('image/jpeg', 0.5),
 blob = dataURItoBlob(dataURL),
 fd = new FormData(document.getElementById('form'));
fd.append("canvasImage", blob);

Here you can read more about this approach Convert Data URI to File then append to FormData

answered Jan 16, 2013 at 14:23

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.