We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Getting file contents

Hello, 

Do you provide any way to get the contents of the uploaded file in binary? I tried using the Uploading and Change properties but the property RawData is empty.

7 Replies

BC Berly Christopher Syncfusion Team June 19, 2019 11:50 AM UTC

Hi Ivan,   

   
Greeting from Syncfusion.   

 
  
While checking the reported issue ("Property RawData is empty."), we would like to inform you that this issue was caused by the missing of ID defined in the control rendering. If you do not provide the component with an ID, a unique ID will be generated automatically. The name attribute will also be generated based on the component's provided ID.
   
So, we suggest that you provide the EJ2 Uploader component ID and access the form data by providing the Uploader component ID as the controller save action argument as mentioned in the example below to get rid of the reported issue. 
  
[index.razor
  
<div> 
    <EjsUploader Id="UploadFiles"> 
            <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings> 
    </EjsUploader> 
</div> 
  
[SampleDataController.cs
  
[HttpPost("[action]")] 
        public IActionResult Save(IList<IFormFile> UploadFiles) 
        { 
            
            IFormFile uploadedImage = UploadFiles.FirstOrDefault(); 
            if (uploadedImage.ContentType.ToLower().StartsWith("image/")) 
            // Check whether the selected file is image 
            { 
                byte[] b; 
                using (BinaryReader br = newBinaryReader(uploadedImage.OpenReadStream())) 
                { 
                    b = br.ReadBytes((int)uploadedImage.OpenReadStream().Length); 
                    // Convert the image in to bytes 
                } 
                Response.StatusCode = 200; 
            } 
            return Content(""); 
        } 
  
Please find the sample from the below link. 
  
If you still have problems, please revert us with the sample to reproduce the issue that will help us to check and provide the exact solution at our end.
   
Regards,   
Berly B.C  



KI Krasimir Ivanov June 22, 2019 10:36 PM UTC

Actually, I was wondering if I could access the binary contents before sending the file collection to the controller. For example, my code is:

@page "/"
@using Syncfusion.EJ2.RazorComponents.Inputs

@this.Temp

<div class="col-lg-12 control-section">
    <div class="control_wrapper">
        <EjsUploader ID="UploadFiles" @ref=this.fileUploadObj DropArea=".control-fluid" Removing="@onFileRemove" AsyncSettings="@asyncSettings"></EjsUploader>
    </div>
</div>

<style>
    .control_wrapper {
        width: 350px;
        margin: 0 auto;
    }
</style>

@code{
    EjsUploader fileUploadObj;

    public object Temp { get; set; }

    public object asyncSettings = new
    {
        saveUrl = "https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save",
        removeUrl = "https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove"
    };

    public void onFileRemove(RemovingEventArgs args)
    {
        args.PostRawFile = false;
    }

    public void OnFileUpload(UploadingEventArgs arg)
    {
        this.Temp = arg.FileData;

        this.Invoke(this.StateHasChanged);
    }

    //public void OnFileChange(object args)
    //{
    //    this.Temp = args;
    //    this.Invoke(this.StateHasChanged);
    //}

    protected override async Task OnAfterRenderAsync()
    {
        await base.OnAfterRenderAsync();

        //this.fileUploadObj.Change = OnFileChange;

        this.fileUploadObj.Uploading = OnFileUpload;
    }
}

I am, however, unable to see the file contents when printing the Temp property.


GG Gopi Govindasamy Syncfusion Team June 24, 2019 08:35 AM UTC

Hi Ivan,  

We are able to reproduce the reported issue and are validating it. We will update you the further details on tomorrow(25th June 2019). 

Please let me know if you have any concern, 

Regards, 
Gopi G. 



GG Gopi Govindasamy Syncfusion Team June 25, 2019 03:18 PM UTC

Hi Ivan,  

Thanks for your patience. 

The reported issue is validated, the cause of the problem is that Blalzor serializer does not serialize the data object of the file type, so the empty object is returned. 

At our end, we verified this as a bug and this fix will be accessible at the end of July 2019. Up until then, we appreciate your patience. From the feedback link below you can track the status of the reported issue. 


Regards, 
Gopi G. 



KI Krasimir Ivanov July 3, 2019 10:34 PM UTC

Do you mean the end of June or the end of July? If it is the second I would like to ask if it is possible for the issue to be fixed earlier.


GG Gopi Govindasamy Syncfusion Team July 4, 2019 10:16 AM UTC

Hi Ivan,  

Thanks for your updating,  

We checked the reported issue, the issue is that the file type does not send to the blazor server straight, so we changed the file to base64 and sent it to the server. Now the event OnUploadStart returns the raw file to the string base64. You can get base64 string straight and convert it to binary object. We are presently working on it and will include the fix in our forthcoming release, which will be available in mid-July 2019. We appreciate your patience so far. 

Regards, 
Gopi G.


BC Berly Christopher Syncfusion Team July 19, 2019 05:29 AM UTC

Hi Ivan, 
  
Thanks for the patience. 
  
We are glad to inform you that “Blazor input files serialization converts {} empty object” has been provided for Uploader component in the 17.2.34-beta version. We request you to upgrade the package to latest version to resolve the reported issue at your end. Please find the release notes details below. 
  
  
  
Regards, 
Berly B.C 


Loader.
Up arrow icon