SuccessEventArgs headers aren't properly formed

Hi, 

Depending on where your Blazor application is running SuccessEventArgs.headers return different values.  So when hosted in Azure for example custom header added during file upload is not at index 1 but at index 0.  How can we read the values by Id?

Azure

content-length: 0
date: Mon, 18 May 2020 12:12:49 GMT
imageurl: https://myUrl
server: Microsoft-IIS/10.0
strict-transport-security: max-age=2592000
x-powered-by: ASP.NET

Local

date: Mon, 18 May 2020 13:22:35 GMT 
imageurl: https://MyUrl
server: Microsoft-IIS/10.0\
status: 200\
x-powered-by: ASP.NET\



1 Reply

BC Berly Christopher Syncfusion Team May 21, 2020 12:22 PM UTC

Hi Alex, 
  
Greetings from Syncfusion support.  
  
We have checked the reported query and would like to inform you that while hosted in the Azure, some additional response will be added in the header for security and cross browser compatibility. Please find the Microsoft documentation to know more about this.  
  
  
So, when we passed the additional parameter to the Uploader component from the controller, we can get that value by finding among all the headers which is available in the response. And this will not change whether it will hosted in azure or local. Kindly refer the below code example. 
  
[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 
            } 
        } 
 
    } 
} 
[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"); 
        } 

  
Please find the sample from the below link. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon