此流mvc不支持超时

时间:2016-09-16 07:09:13

标签: c# asp.net asp.net-mvc file

我经历了关于此例外的大部分问题,但没有一个问题让我知道如何解决我遇到的问题:

  

此流不支持超时

以下是代码:

[ValidateAntiForgeryToken]
[HttpPost]
public async Task<ActionResult> Upload(TemplateOutputModel input)
{
    var result = await Command.ApplyAsync(new UploadDocumentTemplateCommand
    {
        DocumentType = input.DocumentType,
        InputStream = input.File.InputStream,
        ContentLength = input.File.ContentLength,
        FileExtension = ".docx"
    });

    if (result == Command.CommandResult.Succeeded)
         return RedirectToAction("List");
    throw new Exception("Template not uploaded");
}

public class UploadDocumentTemplateCommand:ICommand
{
    public DocumentType DocumentType { get; set;}
    public Stream InputStream { get; set; }
    public int ContentLength { get; set; }
    public string FileExtension { get; set; }
}

public async Task<Command.CommandResult> Apply(UploadDocumentTemplateCommand command)
{
    if (command.ContentLength <= 0) return Command.CommandResult.Failed;
    switch (command.FileExtension)
    {
        case ".pdf":
            documentService.SaveStaticDocument(command.DocumentType, command.InputStream);
            break;
        case ".docx":
            var versionNumber = documentRepository.GetDocumentTemplateVersion(command.DocumentType);
            documentRepository.QuickTemplateUpload(command.DocumentType, command.InputStream, versionNumber + 1);
            break;
    }
    return Command.CommandResult.Succeeded;
}

非常感谢任何帮助。

0 个答案:

没有答案