I´m chunk uploading a file and if I wait until its uploaded and then remove it (by pressing the garbage can) it calls the remove action, and I can remove the file.
But if the user clicks Abort before it has been uploaded the remove action is not fired and I can´t remove the file from the server.
Can you add this or show me how to fire the remove action when pressing abort?
Hi Sturla Þorvaldsson
Greetings from Syncfusion support.
We ensured the reported issue based on the shared details. But unfortunately we were unable to replicate the reported issue in our end. While clicks Abort the remove action is fired. If you are using lowest version of Syncfusion Nuget please upgrade to latest version and ensure in your end. Also we request you to modify the below attached sample to investigate further in our end. Also we have attached recorder output video for your reference.
[Index.razor]
|
@using Syncfusion.Blazor.Inputs
<SfUploader @ref="uploader" ID="chunkFile"> <UploaderEvents OnRemove="OnFileRemove"></UploaderEvents> <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" ChunkSize="50000"></UploaderAsyncSettings> </SfUploader> @code{
SfUploader uploader; public void OnFileRemove(RemovingEventArgs args) { args.PostRawFile = false; } } |
[SampleDataController.cs]
|
public void Remove(string chunkFile) { try { var filename = hostingEnv.ContentRootPath + $@"\{chunkFile}"; if (System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } } catch (Exception e) { Response.Clear(); Response.StatusCode = 200; Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = "File removed successfully"; Response.HttpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase = e.Message; } } |
Regards,
Mohanraj M
Sorry for late response
My problem is that OnFileRemove() in your code doesn´t get called when you press Abort. Its only called when you then press the garbage can.
The same goes for BeforeRemove() on UploaderEvents.
The reason I need this is when I upload a file I have this method FileSelected where I send over in a header a guid (instead of the name).
So I need to send over the guid but I can´t do it when Abort is called and just when delete.
RecordingBlobName is created as a guid and sent over like this
then I get the header and work with it.
So when I press abort there is a partial file that has a guid and I can´t delete it.
The original file name comes over with UploadRecording but I can´t get it through the request headers because Abort doesn´t call the remove events.
So I think this should be fixed by making the event fire also when you press Abort. You don't agree?
Hi Sturla Þorvaldsson,
We suggest to use OnCancel event which will get triggered when file uploading process get aborted. kindly refer the below snippet and API documentation for your reference.
<SfUploader @ref="uploader" ID="chunkFile"> <UploaderEvents OnRemove="OnFileRemove" OnCancel="@OnCancelHandler" ></UploaderEvents> <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" ChunkSize="500"></UploaderAsyncSettings> </SfUploader>
@code{
SfUploader uploader; public void OnFileRemove(RemovingEventArgs args) { args.PostRawFile = false; }
private void OnCancelHandler(CancelEventArgs args) { // Here, you can customize your code. } } |
Documentation: https://blazor.syncfusion.com/documentation/file-upload/events#oncancel
API documentation : https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Inputs.UploaderEvents.html#Syncfusion_Blazor_Inputs_UploaderEvents_OnCancel
Regards,
Mohanraj M
Awesome thanks. This is how I did it. Calle
private async void OnCancelHandler(CancelEventArgs args)
{
var api = _configuration["RemoteServices:Default:BaseUrl"] ?? "";
var request = new HttpRequestMessage(HttpMethod.Post, $"{api}/api/app/stream-events/Remove");
request.Headers.Add("RecordingBlobName", RecordingBlobName);
var client = ClientFactory.CreateClient();
var response = await client.SendAsync(request);
}
Thanks for the update, we are glad to assist you.