How To Upload Large File using postman |Web API to upload Large files |Tutorial in Urdu & English
Video Link:
Copy this code in your Controller :
--------------------------------------------------------------------------------------------------------
[HttpPost]
public async Task<bool> Upload()
{
try
{
var fileuploadPath = ConfigurationManager.AppSettings["UploadFile"];
var provider = new MultipartFormDataStreamProvider(fileuploadPath);
var content = new StreamContent(HttpContext.Current.Request.GetBufferlessInputStream(true));
foreach (var header in Request.Content.Headers)
{
content.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
await content.ReadAsMultipartAsync(provider);
string uploadingFileName = provider.FileData.Select(x => x.LocalFileName).FirstOrDefault();
string originalFileName = String.Concat(fileuploadPath, "\\" + (provider.Contents[0].Headers.ContentDisposition.FileName).Trim(new Char[] { '"' }));
if (File.Exists(originalFileName))
{
File.Delete(originalFileName);
}
File.Move(uploadingFileName, originalFileName);
return true;
}
catch (Exception)
{
return false;
}
}
--------------------------------------------------------------------------------------------------------
Web.Config :
App setting Tag:
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
<add key="UploadFile" value="C:\Users\hdcsa\source\repos\WebApplication6\WebApplication6\Content\UploadedFiles"/>
</appSettings>
Web Server Tag:
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/>
<remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1220933000"/>
</requestFiltering>
</security>
</system.webServer>
0 Comments:
Post a Comment
Do not Add Spam links in the Comment Box
Subscribe to Post Comments [Atom]
<< Home