Size of renaming plupload chunk file to Blob
I am using Plupload to upload a file. The configuration we have is as follows:
$("#uploadData").pluploadQueue({
// General settings
runtimes: 'html5,flash,silverlight,html4',
url: serviceurl,
// Maximum file size
max_file_size: '50mb',
chunk_size: '1mb',
max_file_count: 50,
unique_names: true,
// Resize images on clientside if we can
resize: {
width: 200,
height: 200,
quality: 90,
crop: true // crop to exact dimensions
},
// Specify what files to browse for
filters: [
{ title: "Documents Excel", extensions: "xlsx" }
],
init: {
FilesAdded: function (up, files) {
up.start();
},
UploadComplete: function (up, files) {
if (up.total.uploaded == up.files.length) {
$(".plupload_buttons").css("display", "inline");
$(".plupload_upload_status").css("display", "inline");
up.init();
}
}
},
The problem is when I upload a file larger than 1 MB, I don't get the correct name, instead I get a Blob for the name. For example, my file name is "Test.xlsx" and the size is 2MB, I get on the server side a "blob" for the name, not Test.
Limitation, I cannot change the chuck size limit on the client. How can I get the correct name.
Thanks for your help.
code used to get data from server side:
[System.Web.Mvc.HttpPost]
public ActionResult UploadData(int? chunk, string name)
{
var fileUpload = Request.Files[0];
if (Session["upDataFiles"] == null)
{
Session["upDataFiles"] = new List<FileUploadViewModel>();
}
Session["upDataFiles"] = UpdateTempDataUpload(fileUpload.FileName, name, (List<FileUploadViewModel>)Session["upDataFiles"]);
UploadFile(chunk, name);
return Content("chunk uploaded", "text/plain");
}
private void UploadFile(int? fileChunk, string fileName)
{
var fileUpload = Request.Files[0];
var uploadPath = Server.MapPath("~/App_Data");
var fullPath = Path.Combine(uploadPath, fileName);
fileChunk = fileChunk ?? 0;
using (var fs = new FileStream(Path.Combine(uploadPath, fileName), fileChunk == 0 ? FileMode.Create : FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
var buffer = new byte[fileUpload.InputStream.Length];
fileUpload.InputStream.Read(buffer, 0, buffer.Length);
fs.Write(buffer, 0, buffer.Length);
fs.Close();
}
}
When I check the name in the request.File object, it is blob and not the actual name.
source to share
This issue has been detailed on GitHub . It might be a little confusing, but from what I understand:
- $ _ FILES ['name'] will necessarily "blob" if you are using chunks.
- They seem to be claiming that $ _REQUEST ['name'] should have a real name, but the users seem to disagree.
- As a workaround, it is suggested to send the filename in another form field or url parameter (using for example an event
BeforeUpload
to set this information). You can setmultipart_params
and save your info about the file object you added earlier, or look at the field in your html to get the info at this point.
source to share
To expand on nus's answer a bit:
I used the event BeforeUpload
in Javascript as described in the GitHub post and then had to push the changes to the server.
Earlier, to get the filename I used:
var file = Request.Files[f];
var fileName = file.FileName
However, this was where the " blob
" came back. I made changes instead, so while I was still using Request.Files[f]
for file details, I got the file name like so:
var file = Request.Files[f];
var fileName = Request.Params["name"];
source to share