https://github.com/frankodoom/http_posted_file_helper
A Light-weight Library For Posting Files in Asp.Net. Post files to IIS and Microsoft Azure account with few lines of code.
https://github.com/frankodoom/http_posted_file_helper
asp-net-mvc asynchronous azure-blob azure-storage csharp filebase filehelper fileupload
Last synced: 8 months ago
JSON representation
A Light-weight Library For Posting Files in Asp.Net. Post files to IIS and Microsoft Azure account with few lines of code.
- Host: GitHub
- URL: https://github.com/frankodoom/http_posted_file_helper
- Owner: frankodoom
- Created: 2017-06-11T07:51:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-09-02T17:23:19.000Z (almost 9 years ago)
- Last Synced: 2025-01-27T20:47:59.036Z (over 1 year ago)
- Topics: asp-net-mvc, asynchronous, azure-blob, azure-storage, csharp, filebase, filehelper, fileupload
- Language: C#
- Homepage:
- Size: 48.1 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/HttpPostedFileHelper/)
HTTP Posted File Helper V.1.0.2
This is a light weight library that helps in the posting of files to IIS Webserver by providing a helper class FileHElper.cs which contains overloaded methods ProcessFile() which reduces the boilerplate in posting files.
Installing..
PM> Install-Package HttpPostedFileHelper
Usage
//Reference the Library
using HttpPostedFileHelper;
Processing Single Files (Basic Usage)
```c#
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult UploadFile(HttpPostedFileBase file)
{
//Instanciate the Filehelper class to create a Filehelper Object
FileHelper filehelper = new FileHelper();
filehelper.ProcessFile(file, "{path to Existing or New Directory}");
return view();
};
```
Processing Multiple Files
This makes provision for multiple files being uploaded to the server with an overridden method for Processing an IEnumerable of files (HttpPostedFileBase Collection)
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult UploadFile(Model model, IEnumerable file)
{
FileHelper filehelper = new FileHelper();
// ProcessFileAsync returns count of files processed
int postedfiles = filehelper.ProcessFile(file, "~/MyTargetLocation");
if (postedfiles > 0)
{
//files were written successfully
}
return View("Home");
}
Asynchronous File Processing
Processing files can be done Asynchronously, this allows large files to be processed in the background thread freeing the main thread
[HttpPost]
[ValidateAntiForgeryToken]
public async Task UploadFile(Model model, IEnumerable file)
{
FileHelper filehelper = new FileHelper();
await filehelper.ProcessFileAsync(file, "~/MyTargetLocation");
//you can do some other work while awaiting
return View("Home");
}
Reject File Extensions During Upload
You can specify the file types to be rejected during an upload by supplying a string of the file extensions
[HttpPost]
[ValidateAntiForgeryToken]
public async Task UploadFile(Model model, IEnumerable file)
{
FileHelper filehelper = new FileHelper();
string reject = ".jpeg,.png,.svg";
int postedfiles = await filehelper.ProcessFileAsync(file, "~/MyTargetLocation",reject);
//you can do some other work while awaiting
if (postedfiles > 0)
{
//files were written successfully
}
return View("Home");
}
Uploading Large Files
If you want to upload large files, by default IIS is set to upload files up to 4mb however, you can modify your web.config to allow
upload of your choice.
maxRequestLength
maxAllowedContentLength