调整已在WebAPI控制器

时间:2017-11-28 23:51:08

标签: c# asp.net-web-api asp.net-web-api2

我正在使用multipart/form-data使用await Request.Content.ReadAsMultipartAsync(provider)获取已上传到Web API方法的图片,如下所示:

// Read the form data.
await Request.Content.ReadAsMultipartAsync(provider);

foreach (MultipartFileData item in provider.FileData)
{
    string name = item.Headers.ContentDisposition.FileName.Replace("\"", "");
    newFileName = Guid.NewGuid() + Path.GetExtension(name);
    File.Move(item.LocalFileName, Path.Combine(rootPath, newFileName));
    Uri baseuri = new Uri(Request.RequestUri.AbsoluteUri.Replace(Request.RequestUri.PathAndQuery, string.Empty));
    string fileRelativePath = rootPath + newFileName;
    Uri fileFullPath = new Uri(baseuri, VirtualPathUtility.ToAbsolute(fileRelativePath));
    savedFilePath.Add(fileFullPath.ToString());
    Dictionary<string, string> dictionary = new Dictionary<string, string>();
    dictionary.Add(fieldID, newFileName);
    HttpContext.Current.Session[fieldID] = dictionary;
}

我需要在将图像保存到磁盘之前调整图像大小。我不确定我是否可以在运行时这样做。任何想法?

0 个答案:

没有答案