异步图像文件保存

本文关键字:保存 文件 图像 异步 | 更新日期: 2023-09-27 18:31:37

在 web mvc 项目中。

有以下功能,我正在尝试异步,因为我保存了许多文件,但它有点慢。我是否需要添加到任务列表中并等待所有任务:

   var fs = new FileSaver();
        property.FloorPlanPath = fs.SaveFile(propertyRentalForm.FloorPlanFile, "~/uploads/properties/floorplans");
        property.FloorPlan2Path = fs.SaveFile(propertyRentalForm.FloorPlan2File, "~/uploads/properties/floorplans");
        property.EpcPath = fs.SaveFile(propertyRentalForm.EpcFile, "~/uploads/properties/epc");
    public string SaveFile(HttpPostedFileBase file, string uploadPath)
    {
        if (file == null || file.ContentLength <= 0) return "";
        var fileName1 = Path.GetFileName(file.FileName);
        if (fileName1 == null) return "";
        // clean file name
        fileName1 = string.Format("{0}{1}",
            Path.GetFileNameWithoutExtension(fileName1).GetAliasTitle(),
            Path.GetExtension(fileName1));
        var path = Path.Combine(HttpContext.Current.Server.MapPath(uploadPath), fileName1);
        file.SaveAs(path);
        return fileName1;
    }

异步图像文件保存

如果您有单个磁盘来保存这些文件,则没有使其异步的意义。因为您受到磁盘 I/O 的限制。但是您可以使用队列机制,并且可以异步检查此队列状态...