My apologies if this is an inappropriate question:
My Problem
I'm creating (or attempting to create) a RESTful API for an application that utilizes file uploads primarily for use with a JavaScript client. As many of you know, there's no standard, cross-browser way to upload files using Ajax (outside of the iframe method). Unfortunately, in my application uploading the file requires authentication and so there's no way to use the iframe method that couldn't potentially disrupt the UI.
I obviously could POST to "https://username:password@myhost/resource" but the credentials could then be saved in the browser. Making logging out very difficult.
My Solution
So MY solution is base64 encoding. Which goes as follows:
- Use an iframe to post file to my script (let's call it base64.php)
- That script converts the file to base 64 and then returns the string.
- The application takes the string and sends that in place of the file to my API
- The API takes the base 64 string and converts it back to the file.
- File "upload" complete
Essentially, I use the iframe method to post a file to a script that takes the script, encodes it, and returns the string. I then perform my ajax request as normal using the Base64 encoded string rather then the file itself.
My Question
My question is does anyone see any problems with this solution? Is there a better way? Or is there anything I can do to improve it?
Thanks!