Skip to content

Instantly share code, notes, and snippets.

@kiichi
Last active June 17, 2017 04:28
Show Gist options
  • Select an option

  • Save kiichi/3588880d7217cde2529648ea71e6e65d to your computer and use it in GitHub Desktop.

Select an option

Save kiichi/3588880d7217cde2529648ea71e6e65d to your computer and use it in GitHub Desktop.
[Route("Upload/")]
[HttpPost]
public async Task<object> Upload(string fileName){
string path = Path.GetTempPath();
var provider = new MultipartFormDataStreamProvider(path);
await Request.Content.ReadAsMultipartAsync(provider);
var tmpFilePath = provider.FileData.Select(entry => entry.LocalFileName).First();
var targetFilePath = Path.Combine(@"C:\tmp\", fileName);
File.Copy(tmpFilePath,targetFilePath);
return fileName + " has been saved on " + targetFilePath + " via " + tmpFilePath;
}
  • url: (your test url)/Upload/?fileName=hello2.jpg

  • method: POST

  • Body -> form-data

  • Key could be blank but select file type. In value, select a file.

<system.web>
<httpRuntime maxRequestLength="30000000" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="30000000" />
</requestFiltering>
</security>
</system.webServer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment