用Fine Uploader上传文件块,我无法将它们合并在一起

本文关键字:在一起 合并 Uploader Fine 文件 | 更新日期: 2023-09-27 18:07:04

我正在试验Fine Uploader,以便在我们的网站上实现它。我真的很喜欢分块和简历功能,但是我在服务器端把文件放回一起时遇到了一些问题;我这么做之后,他们就腐败了。经过一番调查,我发现每个块都大了194个字节,这使得生成的文件大了x 194个字节。这是已知的问题吗?如果需要,我会张贴我的代码。谢谢你的宝贵时间。

EDIT这是我的sscce。我忘了说明我用的是ASP。净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();
    }    
}

用Fine Uploader上传文件块,我无法将它们合并在一起

问题是在我解析输入流(在我的c#处理程序类)的方式从请求对象的各个块,

我读它的方式:

System.IO.Stream inputStream = request.InputStream;

阅读方式:

System.IO.Stream inputStream = request.Files[0].InputStream;

这个google群组帖子建议第二种方式应该只在IE中完成,而第一种方式在所有其他浏览器中完成,但我发现它在所有浏览器中都是这样的