|
[HttpPost("[action]")]
public async void Save(IList<IFormFile> UploadFiles)
{
try
{
foreach (var file in UploadFiles)
{
if (UploadFiles != null)
{
var filename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
filename = hostingEnv.WebRootPath + $@"\{filename}";
if (!System.IO.File.Exists(filename))
{
using (FileStream fs = System.IO.File.Create(filename))
{
file.CopyTo(fs);
fs.Flush();
}
}
else
{
Response.Clear();
Response.StatusCode = 204;
Response.Headers.Add("ID", "File already exists.");// Assign the custom data in the response header.
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File already exists.";
}
}
}
}
catch (Exception e)
{
Response.Clear();
Response.ContentType = "application/json; charset=utf-8";
Response.StatusCode = 204;
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload";
Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message;
}
} |
|
public void OnSuccess(SuccessEventArgs args)
{
//Also, you can send the status from the server in header and receive in the success event
var customHeader = args.Response.Headers.Split(new Char[] { '\r' })[1]; // To split the response header values
var value = customHeader.Split(new Char[] { ':' })[1].Trim(); // To get the value for the key pair of provided custom data in header
if (value.Contains("exists"))
{
args.StatusText = value;
}
} |
I added in my startup.cs file the following lines from your sample but adding them my application doesn't start giving me the error message I share you in attachment togheter with my startup.cs fileI'm using BoldReports and I suppose there's a sort of incompatibility because without the lines below my application startsservices.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);app.UseMvcWithDefaultRoute();
Attachment: Startup_e2458265.zip
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
})but the line endpoints.MapControllers(); is in conflict with the use of app.UseMvcWithDefaultRoute();How can I use both ?|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
// app.UseMvcWithDefaultRoute();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("default", "{controller=SampleData}/{action=Save}");
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
} |
|
public void OnSelect(SelectedEventArgs args)
{
foreach(var file in args.FilesData)
{
var name = file.Name;
}
} |