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

Cannot remove files via custom method

Hello,

I am trying to remove files by attaching a method to the OnRemove delegate of a file upload object. It looks like this.fileUploadObj.OnRemove = OnFileRemove; . However, the method OnFileRemove is not invoked when I remove a file. The same issue is not valid for the OnUploadtStart property.

3 Replies

BC Berly Christopher Syncfusion Team July 26, 2019 01:36 PM UTC

Hi Krasimir, 
  

Greetings from Syncfusion support.  

  
While checked the reported query, we suspect that you have bind the success and remove event on the custom method in the “OnInit” method. In this case, our Blazor component will not render and Uploader object will be null. This may be the root cause of the reported issue at your end. So, we suggest you to bind the custom method for the success and removing event in “OnAfterRender” as mentioned in the below code example.  

  
[index.razor

<EjsUploader @ref="fileUploadObj" ID="UploadFiles"> 
    <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings> 
</EjsUploader> 
<div> 
    <p>Uploaded File Name is: @FileName</p> 
    <p>Removed File Name is: @Removing</p> 
</div> 
@code{ 
EjsUploader fileUploadObj; 
public string FileName; 
public string Removing; 
public void OnSuccess(object args) 
{ 
    //Deserialized the success event args using Newton soft. 
    SuccessEventArgs eventArgs = JsonConvert.DeserializeObject<SuccessEventArgs>(args.ToString()); 
    // Assign the file name in the variable 
    FileName = eventArgs.File.Name; 
    // To reflect the DOM content 
    this.StateHasChanged(); 
} 
//Success event args class. 
public class SuccessEventArgs 
{ 
    public object E { get; set; } 
    public FileInfo File { get; set; } 
    public string StatusText { get; set; } 
    public string Name { get; set; } 
    public string Operation { get; set; } 
    public ResponseEventArgs Response { get; set; } 
} 
 
public class ResponseEventArgs 
{ 
    public string Headers { get; set; } 
    public object ReadyState { get; set; } 
    public object StatusCode { get; set; } 
    public string StatusText { get; set; } 
    public bool withCredentials { get; set; } 
} 
public void OnFileRemove(RemovingEventArgs args) 
{ 
    Removing = args.FilesData[0].Name; 
    StateHasChanged(); 
} 
 
 
protected override void OnAfterRender() 
{ 
    this.fileUploadObj.OnRemove = this.OnFileRemove; 
    this.fileUploadObj.Success = this.OnSuccess; 
} 
} 


  
Please find the sample from the below link. 

 
  
Regards, 
Berly B.C 



KI Krasimir Ivanov July 26, 2019 02:13 PM UTC

My OnRemove method is bound inside the OnAfterRender method. Could you check if it works for you? Thank you in advance.


BC Berly Christopher Syncfusion Team July 29, 2019 07:14 AM UTC

Hi Krasimir, 
  

We would like to inform you that, In our last update we have bind the OnRemove method inside the OnAfterRender method. Can you please check the below code example and let us know if you need any other customization that will help us to check and provide the prompt solution? 

  
[index.razor

<EjsUploader @ref="fileUploadObj" ID="UploadFiles"> 
    <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove"></UploaderAsyncSettings> 
</EjsUploader> 
<div> 
    <p>Uploaded File Name is: @FileName</p> 
    <p>Removed File Name is: @Removing</p> 
</div> 
@code{ 
EjsUploader fileUploadObj; 
public string FileName; 
public string Removing; 
protected override void OnAfterRender() 
{ 
    this.fileUploadObj.OnRemove = this.OnFileRemove; 
    this.fileUploadObj.Success = this.OnSuccess; 
} 
public void OnFileRemove(RemovingEventArgs args) 
{ 
    Removing = args.FilesData[0].Name; 
    StateHasChanged(); 
} 
public void OnSuccess(object args) 
{ 
    //Deserialized the success event args using Newton soft. 
    SuccessEventArgs eventArgs = JsonConvert.DeserializeObject<SuccessEventArgs>(args.ToString()); 
    // Assign the file name in the variable 
    FileName = eventArgs.File.Name; 
    // To reflect the DOM content 
    this.StateHasChanged(); 
} 
//Success event args class. 
public class SuccessEventArgs 
{ 
    public object E { get; set; } 
    public FileInfo File { get; set; } 
    public string StatusText { get; set; } 
    public string Name { get; set; } 
    public string Operation { get; set; } 
    public ResponseEventArgs Response { get; set; } 
} 
 
public class ResponseEventArgs 
{ 
    public string Headers { get; set; } 
    public object ReadyState { get; set; } 
    public object StatusCode { get; set; } 
    public string StatusText { get; set; } 
    public bool withCredentials { get; set; } 
} 
} 

 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon