当我使用以下代码时,文件在 中正确上传uploadPath
,但该GetLocalFileName
方法返回错误的BodyPart
名称。
文件名中的 guid(例如BodyPart_f4a1e725-0194-4bda-a666-b6ffea7b0618
:)将是其他一些不是刚刚上传的文件的 guid。
我正在尝试获取上传文件的文件名。
private string lastUploadFileName
public async Task AsyncReceive(HttpRequestMessage incomingRequest)
{
request = incomingRequest;
streamProvider = new MultipartFormDataStreamProvider(uploadPath);
var uploadTask = request.Content.ReadAsMultipartAsync(streamProvider);
await uploadTask.ContinueWith(t =>
{
if (t.IsFaulted || t.IsCanceled)
{
throw new Exception("Error uploading file.");
}
});
lastUploadFileName = streamProvider.GetLocalFileName(
request.Content.Headers);
}