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

Flash runtime does not write an extra CR/LF to end of the multipart request #37

Open
stevenkuhn opened this issue Jun 13, 2013 · 3 comments

Comments

@stevenkuhn
Copy link

I'm attempting to use plupload 2.0 to upload files to a .NET WebAPI server and there is an issue with the Flash runtime not writing an extra CR/LF to end the multipart request. Technically, it's not required, but the .NET WebAPI runtime breaks if the request does not end with a CR/LF (see this issue and this discussion on CodePlex). It doesn't look like they are not going to fix the problem on their end either. 👎

The following is an example request sent from the Flash runtime:

POST http://localhost:38893/api/upload HTTP/1.1
Host: localhost:38893
Connection: keep-alive
Content-Length: 634
Origin: http://localhost:38893
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Content-Type: multipart/form-data; boundary=----------gL6cH2GI3GI3Ef1Ij5Ij5cH2gL6KM7
Accept: */*
Referer: http://localhost:38893/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

------------gL6cH2GI3GI3Ef1Ij5Ij5cH2gL6KM7
Content-Disposition: form-data; name="Filename"

cldbuild02.rdp
------------gL6cH2GI3GI3Ef1Ij5Ij5cH2gL6KM7
Content-Disposition: form-data; name="name"

cldbuild02.rdp
------------gL6cH2GI3GI3Ef1Ij5Ij5cH2gL6KM7
Content-Disposition: form-data; name="file"; filename="cldbuild02.rdp"
Content-Type: application/octet-stream

full address:s:cldbuild02:3389
username:s:Administrator
prompt for credentials:i:1


------------gL6cH2GI3GI3Ef1Ij5Ij5cH2gL6KM7
Content-Disposition: form-data; name="Upload"

Submit Query
------------gL6cH2GI3GI3Ef1Ij5Ij5cH2gL6KM7--

And here is the request using the HTML5 runtime:

POST http://localhost:38893/api/upload HTTP/1.1
Host: localhost:38893
Connection: keep-alive
Content-Length: 412
Origin: http://localhost:38893
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryqrB60GCabhnOAE2F
Accept: */*
Referer: http://localhost:38893/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8

------WebKitFormBoundaryqrB60GCabhnOAE2F
Content-Disposition: form-data; name="name"

cldbuild02.rdp
------WebKitFormBoundaryqrB60GCabhnOAE2F
Content-Disposition: form-data; name="file"; filename="cldbuild02.rdp"
Content-Type: application/octet-stream

full address:s:cldbuild02:3389
username:s:Administrator
prompt for credentials:i:1


------WebKitFormBoundaryqrB60GCabhnOAE2F--

Both the HTML5 and Silverlight runtimes give that extra CR/LF at the end of the request. Can the Flash runtime be changed to output it as well?

Thanks!

@jayarjo
Copy link
Contributor

jayarjo commented Jun 14, 2013

I'm afraid this is a problem with default upload method in Flash. We do not have any control over it. But we have another, artificial mode, where we build multipart request ourselves and the result gets consistent across the runtimes. You can forcefully switch to it by explicitly requesting send_binary_string capability.

However it is only applicable to files smaller than 200-300mb, since this method requires the file to be preloaded first. It is a case specific to Flash only.

Are you using this component as a part of Plupload, or you are building directly on top of it? I can provide better example, if you post more details about your usage case.

@stevenkuhn
Copy link
Author

Thanks for the update @jayarjo! :) My use case is that I am using the Plupload custom upload feature to allow users to upload log files which normally range in the 1-2 GB range. For the server-side, I'm running ASP.NET on IIS using the new Web API framework. My initial set up of Plupload is this:

var uploader = new plupload.Uploader({
    browse_button: 'add-file',
    flash_swf_url: '/Scripts/Moxie.swf',
    max_file_size: '2gb',
    max_retries: 3,
    multi_selection: true,
    runtimes: 'html5,flash,silverlight',
    silverlight_xap_url: '/Scripts/Moxie.xap',
    url: '/api/upload'
});

uploader.init();

// all events are bound here (i.e. FilesAdded, UploadProgress, Error, etc).

My initial idea was to just upload the entire file, but once I have that working I would add chunking and resumable upload support. Would splitting the 2gb file into 200-300mb chucks help?

To give you an idea on our usage: with our old system we currently have up to 10-15 total simultaneous uploads across all users at any given time. We could see an increase in that with this new implementation, but it should support at least that.

Thanks for the help!

EDIT: I changed the description to mention that Microsoft will probably not fix the issue on their end.

@jayarjo
Copy link
Contributor

jayarjo commented Jun 15, 2013

It doesn't look like Adobe will fix it either. I'd probably recommend to simply ignore the Flash runtime the (1-2gb is too much), chunking will not help, since it still requires the file to be preloaded in memory (only in the case of Flash).

Anyway this is how you can force it to our artificial multipart mode:

var uploader = new plupload.Uploader({
    browse_button: 'add-file',
    flash_swf_url: '/Scripts/Moxie.swf',
    max_file_size: '2gb',
    max_retries: 3,
    multi_selection: true,
    runtimes: 'html5,flash,silverlight',
    silverlight_xap_url: '/Scripts/Moxie.xap',
    url: '/api/upload',
    required_features: 'send_binary_string'
});

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

No branches or pull requests

2 participants