Best way to handle images upload when creating a post
i am building a little social site, currently i am having issues with the image upload section. i want the user to be able to optionally upload an image while creating a post, right now i am loading the images to the browser as base64 strings then when the user hits post, i use ajax to send the post and the image string to the server, then convert the image back to jpeg. it seemed to be working well for small images but when large images are "attached " to the browser for submission to the server, i begin to notice a drastic drop in the browser performance ( due the large image size). okay so my question is what better options do i have to implement this functionality. if i want to go with the option of uploading the image to the server through ajax immediately the user adds it, how do i handle situations when the user did not complete writing the post and submit it ?
Why all the converting to base64 and back? Why don't you just use a <input type="file"> ?
I solved the direct uploading with DropzoneJS ( www.dropzonejs.com )
I upload the images to a temp folder, and when the user finishes his post, I move it from there to the final image folder. If the user doesn't finish his post, the image stays in the temp folder, and with every upload I check if there are files older than 2 days - if there are, I delete them.