How to convert base64 encoded string into a file input to be uploaded as an image
I want to be able to take a base64 encoded string and mimic it as if it were a file that i selected it from the "browse" feature. Here is a short example:
<input type="file" id="file" /> <script> //I want to be able to access it here $("#file").files; </script>
I want to be able to access the files array and use it as a normal file. I currently get the base64 encoded string like so:
// resize the canvas and draw the image data into it var canvas = document.createElement('canvas'); canvas.width = width; canvas.height = height; var ctx = canvas.getContext("2d"); ctx.drawImage(img, 0, 0, width, height); preview.appendChild(canvas); // do the actual resized preview var base64String = canvas.toDataURL("image/jpeg", 0.7);
File elements are only usable by the user, you would need to transfer the base64 string as normal form submission and then decode it on the server.