Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File without parameter name in post request #63

Open
parnager opened this issue Dec 22, 2016 · 1 comment
Open

File without parameter name in post request #63

parnager opened this issue Dec 22, 2016 · 1 comment
Labels

Comments

@parnager
Copy link

Hi,
thanks for your work, FileDrop works nice all in all. But I have a problem with the Request. My Server requires a param name for the file, such as ID__file and the binary data connected to that. Otherwise I found no possibility, to read the file contents and read it in Java.
Is there any possibility (without using the iframe solution) to give the file in the post request a custom parameter name? I already used iframe.fileParam, but as the name says, it's not really what I need.

If there is no possibility, do you have any ideas or examples, how to read the file data with a java servlet?

In the image below, i have on the upper side a screenshot of our old, working request.
On the lower side there is the request sent by FileDrop, where I passed some parameters in the url (working) but the file data is just located in the post request.

I would be grateful for any ideas.

gutschlecht

kind regards,
Bernhard

@ProgerXP
Copy link
Owner

ProgerXP commented Dec 22, 2016

Is there any possibility (without using the iframe solution) to give the file in the post request a custom parameter name?

No, this is browser's limitation. FileDrop was written to support quite old browsers and by that time the spec was implemented so that if you want to send a file chosen by the user (via the open file dialog) then you have to send it as a complete POST data, you can't customize it in any way. If you look at the source code, you will see something like xmlHttpRequest.send(fileObject) - in contrast to how you normally submit POST XHR (a=b&c=d etc.).

With modern browsers that properly implement File API (most of them, even IE to some point) it's possible to work with file objects directly, i.e. read their data from any offset and of any length. Therefore you can read entire file into a string and construct a normal multipart POST data as you would like. It will work for small files all right but not for big files because it'll eat up memory and be slow.

Using xhr.send(file) is still the most straightforward way because 1) old browsers support it, 2) browser handles memory and all other issues itself. The only downside is that you can't control the form of POST data exactly. In PHP and ASP you have access to raw POST data, don't you have it in JSP?

It's still possible to add custom request parameters to this kind of request, just use GET query part (as seen on some FileDrop demos), i.e. add ?foo&bar... to the upload script URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants