aspnetcore vue 下载zip文件,压缩包打不开的问题记录
C#代码压缩传输zip文件
测试用:
// POST api/<LogFileDownloadController>
[HttpPost]
public FileResult Post([FromBody] LogFileDownloadInputModel value)
{
var uuidN = Guid.NewGuid().ToString("N");
String basePath = AppContext.BaseDirectory;
string folderPath = basePath + "FileTemp"+ uuidN;
string sourceDisk = "L:\\";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
List<string> filelist = new List<string>();
foreach (string relativepath in value.relativepaths)
{
string fileAbsolutePath = sourceDisk + relativepath.Replace("/","\\");
if (System.IO.File.Exists(fileAbsolutePath))
{
System.IO.File.Copy(fileAbsolutePath, folderPath + "\\" +QstringFunction.SubLastAfter(fileAbsolutePath,"\\"));
filelist.Add(folderPath + "//" + QstringFunction.SubLastAfter(fileAbsolutePath, "\\"));
}
else
{
}
}
if (value.relativepaths.Count<1)
{
return null;
}
bool isSuc = YG._CommonFunctions.ZipHelper.CompressMulti(filelist, folderPath+"\\"+ uuidN + ".zip", true,false);
if (System.IO.File.Exists(folderPath + "\\" + uuidN + ".zip"))
{
var _zip= folderPath + "\\" + uuidN + ".zip";
var stream = System.IO.File.OpenRead(_zip);
string fileExt = Path.GetExtension(uuidN + ".zip");
var provider = new FileExtensionContentTypeProvider();
var memi = provider.Mappings[fileExt];
return File(stream, memi, Path.GetFileName(_zip));
}
else
{
return null;
}
}
如果zip压缩包打不开,显示损坏,需要在下面加上
responseType: 'blob',