/// <summary> /// 文件分块上传,适合大文件 /// </summary> /// <param name="file"></param> /// <returns></returns> private string MultipartUpload(BaseUploadParameter param) { Stream stream = param.Stream; byte[] content = param.Content; //注意此处抛出一个架构级异常 if (stream == null && content == null) { throw new ArgumentNullException("stream及content参数不能同时为空"); } //1 若传入的参数对象中二进制数组为空,说明将文件内容读取至流对象中 if (content == null) { content = new byte[SIZE]; Stream streamUpload = stream; //将流以二进制的形式读取出来 streamUpload.Read(content, 0, SIZE); } //2 第一个数据包上传或获取已上传的位置 string ext = param.FileName.Substring(param.FileName.LastIndexOf('.') + 1); string shortName = FastDFSClient.UploadAppenderFile(Node, content, ext); BeginUploadPart(stream, shortName); return(CompleteUpload(stream, shortName)); }
/// <summary> /// 文件分块上传,适合大文件 /// </summary> /// <param name="file"></param> /// <returns></returns> private string MultipartUpload(Stream stream, string ext) { if (stream == null) { throw new ArgumentNullException("stream参数不能为空"); } int size = 1024 * 1024; byte[] content = new byte[size]; // 第一个数据包上传或获取已上传的位置 stream.Read(content, 0, size); string shortName = FastDFSClient.UploadAppenderFile(Node, content, ext); BeginUploadPart(stream, shortName, size); return(CompleteUpload(stream, shortName)); }
/// <summary> /// 文件分块上传,适合大文件 /// </summary> /// <param name="file"></param> /// <returns></returns> private string MultipartUpload(UploadParameterBase param) { Stream stream = param.Stream; if (stream == null) { throw new ArgumentNullException("stream参数不能为空"); } byte[] content = new byte[SIZE]; Stream streamUpload = stream; // 第一个数据包上传或获取已上传的位置 string ext = param.FileName.Substring(param.FileName.LastIndexOf('.') + 1); streamUpload.Read(content, 0, SIZE); string shortName = FastDFSClient.UploadAppenderFile(Node, content, ext); BeginUploadPart(stream, shortName); return(CompleteUpload(stream, shortName)); }