I really like aspnetboilerplate framework, I learning/using it now..
How do you do \'File Upload\' logic/method in AppServices for aspnetboilerplate? The angular par
All application services have access to the HttpContext object, so they are also able to handle file upload. To upload a file to an app. service make sure to use the correct url + headers.
App. service example:
public class MyUploadService : MyApplicationBaseClass, IMyUploadService
{
///
/// References the logging service.
///
private readonly ILogger _logger;
///
/// Construct an new instance of this application service.
///
public MyUploadService(ILogger logger)
{
_logger = logger;
}
///
/// Method used to handle HTTP posted files.
///
public async Task Upload()
{
// Checking if files are sent to this app service.
if(HttpContext.Current.Request.Files.Count == 0)
throw new UserFriendlyException("No files given.");
// Processing each given file.
foreach(var file in HttpContext.Current.Request.Files)
{
// Reading out meta info.
var fileName = file.fileName;
var extension = Path.GetExtension(file.FileName);
// Storing file on disk.
file.SaveAs("~/uploads");
}
}
}