当我从C#接收到iformfile的文件时,如何知道该文件的文件路径?如果我不知道,我该怎么办?
public async Task<JObject> files(IFormFile files){
string filePath = "";
var fileStream = System.IO.File.OpenRead(filePath)
}发布于 2020-10-22 06:22:14
在本文件中,介绍了关于IFormFile的一些说明:
使用IFormFile技术上传的文件在处理前会被缓冲在内存或服务器上的磁盘上。在action方法中,IFormFile内容可以作为流访问。
因此,对于IFormFile,在使用本地路径之前,需要在本地保存它。
例如:
// Uses Path.GetTempFileName to return a full path for a file, including the file name.
var filePath = Path.GetTempFileName();
using (var stream = System.IO.File.Create(filePath))
{
// The formFile is the method parameter which type is IFormFile
// Saves the files to the local file system using a file name generated by the app.
await formFile.CopyToAsync(stream);
}在此之后,您可以获得本地文件路径,即filePath。
https://stackoverflow.com/questions/64474442
复制相似问题