[SampleDataController.cs] [HttpPost("[action]")] public void Save(IList<IFormFile> chunkFile, IList<IFormFile> UploadFiles) { long size = 0; try { foreach (var file in UploadFiles) { var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); var folders = filename.Split('/'); var uploaderFilePath = hostingEnv.ContentRootPath; // for Directory upload if (folders.Length > 1) { for (var i = 0; i < folders.Length - 1; i++) { var newFolder = uploaderFilePath + $@"\{folders[i]}"; Directory.CreateDirectory(newFolder); uploaderFilePath = newFolder; filename = folders[i + 1]; } } filename = uploaderFilePath + $@"\{filename}"; size += file.Length; if (!System.IO.File.Exists(filename)) { using (FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); }
} } } catch (Exception e) { Response.Clear(); Response.StatusCode = 204; Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File failed to upload"; Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message; } Response.Headers.Add("ID", "Failure"); } [index.razor] @using Syncfusion.Blazor.Inputs
<SfUploader ID="UploadFiles" AutoUpload="false"> <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings> <UploaderEvents Success="OnSuccess"></UploaderEvents> </SfUploader> <p>key value is: @key</p> <p>pair value is: @value</p> @code {
public string customHeader { get; set; } = ""; public string key { get; set; } = ""; public string value { get; set; } = "";
public void OnSuccess(Syncfusion.Blazor.Inputs.SuccessEventArgs args) { var customHeader = new string[] { }; customHeader = args.Response.Headers.Split(new Char[] { '\n' }); // To split the response header values for (var i =0; i< customHeader.Length; i++) { if(customHeader[i].Split(new Char[] { ':' })[0] == "id") { key = customHeader[i].Split(new Char[] { ':' })[0]; // To get the key pair of provided custom data in header value = customHeader[i].Split(new Char[] { ':' })[1].Trim(); // To get the value for the key pair of provided custom data in header } }
}
} |
Hi support.
I'm in the same situation as DotCom is. Or even worst. My 'arg.Response.Headers' where fine in 'onSuccess' one week ago!.
Then, suddently 'arg.Response.Headers' is just showing a "content type 0\r\n" string.
- Nothing has changed in my code since.
- Your example works fine, even with .NET 6 and Syncfusion 19.4.0.38, with IIS and Kestrel, all combinations.
- When I upload a file, I can see the right response headers in Chrome > console > network.
is there anything that I should consider in my program.cs or elsewere that I'm doing wrong? Has DotCom succeded with this?
Thank you so much.
Hi again.
I've prepared the sample for you. There is an index page with a browser. Just upload the file.
There are 2 points of interest, both with the comment "FOR SYNCFUSION" in the code.
1. The controller that adds the header on upload.
2. Your SFUpload onSuccess method that receives the header.
The header appears to be empty.
- I've removed all authentication to make this simple and clean.
- I've added a password in the zip file (as there is some third party licensed html inside). Please, tell me where to send this password.
- Please, start both projects with 'multiple project startup'
Thank you for your support.
Hi Ponmani.
You will need me to send you a password for the ZIP file. Would you send me instructions?
Thank you.
Hi Ponmani.
Do you have any news about this issue?
Thank you
Xavi.
|
services.AddCors(options =>
{
options.AddDefaultPolicy(
builder =>
{
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
.WithExposedHeaders("*");
});
}); |
Ponmani.
It worked! This was the solution "WithExposedHeaders("*")", no need to allow credentials.
Thank you for your great support!
Hey,
Is there an update on this ?
Is this still the recommended way of sending a response to the client ? I am surprised there is not an elegant way of simply returning JSON in the body.
Thank you
Hi Vlad Andronache,
We would like to inform you that you can retrieve custom headers from the server to the client using the above approach provided in this forum. For further information on passing custom headers from the server to the client, please refer to the following forum.
Forum: https://www.syncfusion.com/forums/153677/get-response-when-upload-file
We have already considered this request “Provide support for catch the returned response body in uploader component” as feature from our end and the this will be implemented with our upcoming Volume 2 main release which is expected to be scheduled on June 28th, 2024.
You can track the status of this report through the following feedback link,
Feedback link: https://www.syncfusion.com/feedback/42492/need-to-provide-support-to-display-the-selected-items-as-chips-when-using
Regards,
Yohapuja S