当我使用以下代码时,该文件已在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);
}