box/box-java-sdk-v2 — pull request #200 by mmorearty (2014-09-08 20:33:23+00:00)
Title: Improvements to file upload

This patch includes three interrelated changes to the Box API request that is made when uploading a file.

First, there are two changes to the Content-Disposition header. The old header looked like this:

Content-Disposition: form-data; name="myfile.txt"; filename="myfile.txt"

`name="myfile.txt"` is wrong; it is supposed to say `name="filename"`.

`filename="myfile.txt"` is okay as long as the filename does not contain any accented character or any double-quote characters; but if contains either of those, then there could be problems. In HTTP there is no reliable way to escape the filename in the Content-Disposition header. So instead, the Java SDK sends an additional JSON section named "metadata" (which is available for any Box API client to use) to send the filename. Since it is UTF-8 JSON, it is safe to include any characters in the filename there. So, with this change, the Content-Disposition header always just says `filename="placeholder.txt"`.

So with these two changes together, the Content-Disposition header now looks like this:

Content-Disposition: form-data; name="filename"; filename="placeholder.txt"

The final change is that when uploading a new file, the part that contains the destination folder id is now always sent *before* the part that contains the actual contents of the file. This allows Box's back-end infrastructure to more efficiently stream the file to its final destination (since the final destination may depend on the folder to which it is being written).