我正在试验 Fine Uploader 以便在我们的网站上实施它。我真的很喜欢分块和恢复功能,但是我在将文件重新放在服务器端时遇到了一些问题;我这样做后他们就腐败了。经过一番调查,我发现每个块都太大了 194 字节,这使得生成的文件太大了 x 194 字节。这是一个已知问题吗?如果需要,我会发布我的代码。谢谢你的时间。
编辑这是我的 sscce。我忘了指定我使用的是 ASP.NET C#。
网页上传器的初始化
$(document).ready(function () {
var manualuploader = new qq.FineUploader({
element: $('#fine-uploader')[0],
request: {
endpoint: 'UploadHandler.ashx',
forceMultipart: true
},
chunking: {
enabled: true
},
resume: {
enabled: true
},
retry: {
enableAuto: true
},
callbacks: {
onSubmit: function (id, fileName) {
document.getElementById('triggerUpload').style.visibility = 'visible';
}
}
});
});
和服务器端处理程序(c#):
<%@ WebHandler Language="C#" Class="UploadHandler" %>
using System;
using System.Web;
public class UploadHandler : IHttpHandler, System.Web.SessionState.IReadOnlySessionState
{
private int completed;
public void ProcessRequest(HttpContext context)
{
HttpRequest request = context.Request;
string partIndex = request.Params["qqpartindex"];
int totalParts = Convert.ToInt32(request.Params["qqtotalparts"]);
String filename = request.Params["qqfilename"];
String totalFileSizeName = request.Params["qqtotalfilesize"];
string uploadedTemp = context.Server.MapPath("~/App_Data/" + "TEMP/");
string uploadedLocation = context.Server.MapPath("~/App_Data/");
string filePath = System.IO.Path.Combine(uploadedTemp, partIndex + ".tmp");
if (!System.IO.File.Exists(filePath))
{
System.IO.Stream inputStream = request.InputStream;
using (System.IO.FileStream fileStream = System.IO.File.OpenWrite(filePath))
{
inputStream.CopyTo(fileStream);
}
}
completed = 0;
if (partIndex.Equals(Convert.ToString(totalParts - 1))) // all chunks have arrived
{
mergeTempFiles(uploadedTemp, uploadedLocation, filename);
completed = 1;
}
context.Response.ContentType = "application/json";
context.Response.Write("{\"success\":true, \"completed\": " + completed +"}");
}
public bool IsReusable
{
get { return true; }
}
public void mergeTempFiles(string pathOrigin, string pathToSave, string filename)
{
string[] tmpfiles = System.IO.Directory.GetFiles(pathOrigin, "*.tmp");
if (!System.IO.Directory.Exists(pathToSave))
{
System.IO.Directory.CreateDirectory(pathToSave);
}
System.IO.FileStream outPutFile = new System.IO.FileStream(pathToSave + filename, System.IO.FileMode.Create, System.IO.FileAccess.Write);
foreach (string tempFile in tmpfiles)
{
int bytesRead = 0;
byte[] buffer = new byte[1024];
System.IO.FileStream inputTempFile = new System.IO.FileStream(tempFile, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Read);
while ((bytesRead = inputTempFile.Read(buffer, 0, 1024)) > 0)
outPutFile.Write(buffer, 0, bytesRead);
inputTempFile.Close();
//System.IO.File.Delete(tempFile);
}
outPutFile.Close();
}
}