MIME多部分流的意外结束。当覆盖Stream::GetStream
MultipartFormDataStreamProvider
方法时,MIME多部分消息未完成错误。我在GetStream
方法中获取流并对其进行加密并返回它而不是它给我这个错误(MIME多部分流的意外结束)。我已经完成了所有以前的解决方案,但是没有用。
这是我的代码:
var Savedfiledata = await Request.Content.ReadAsMultipartAsync(provider).ContinueWith(
(Task<CustomMultipartFormData> readTask) =>
{
CustomMultipartFormData CMF = readTask.Result;// Here Error is comming
// Create response containing information about the stored files.
return CMF.FileData.Select(fileData =>
{
FileInfo info = new FileInfo(fileData.LocalFileName);
ContentDispositionHeaderValue disposition = fileData.Headers.ContentDisposition;
string filename = (disposition != null && disposition.FileName != null) ? disposition.FileName : string.Empty;
CS_FileUpload FileObj = new CS_FileUpload()
{
FileName = filename.Replace("\"", ""),
FileUniqueName = info.Name,
FileSize = (info.Length / 1024),
FilePath = info.DirectoryName,
FileType = info.Extension,
InsertDate = info.LastWriteTimeUtc,
};
DAObj.CS_FileUpload.Add(FileObj);
return FileObj;
}).ToList();
});
公共覆盖Stream GetStream(HttpContent filedata,HttpContentHeaders标头) {
Stream reqStream = filedata.ReadAsStreamAsync().Result;
using (MemoryStream stream = new MemoryStream())
{
reqStream.CopyTo(stream);
MemoryStream getEncBytes = Encrypt(stream, GenerateKey());
return getEncBytes;
}
}