Sending only filename on remove action

How can I send only the filename and not the whole file on Remove. The API action is called but UploadFiles is null. When I set PostRawFile = true; and IList<IFormFile> UploadFiles as parameter it is working.

Can you send me a sample project of only sending F

My BeforeRemove method


public static void BeforeRemove(BeforeRemoveEventArgs beforeRemoveEventArgs, string rawAccessToken,Type type)
            {
                beforeRemoveEventArgs.PostRawFile = false;
                var accessToken = $"Bearer {rawAccessToken}";
                beforeRemoveEventArgs.CurrentRequest = new List<object> { new { Authorization = accessToken }, new { Caller = FileUploadHelper.GetTempDirectory(type) } };


            }

My component

<SfUploader ID="UploadFiles"
                            AllowMultiple=false>
                    <UploaderAsyncSettings SaveUrl="@FileUploadHelper.SaveDirectory.CompanyDocument"
                                           RemoveUrl="api/Files/Remove/">
                    </UploaderAsyncSettings>
                    <UploaderEvents FileSelected="@((args)=>AdminHelper.SfUploadHelper.OnFileSelect(args,grid.AccessToken))"
                                    Success="@((args)=>(context as CompanyDocument).FileLink=AdminHelper.SfUploadHelper.UploadSuccess(args))"
                                    BeforeRemove="@((args)=>AdminHelper.SfUploadHelper.BeforeRemove(args,grid.AccessToken,typeof(CompanyDocument)))">
                    </UploaderEvents>
                </SfUploader>

My controller

[HttpPost("[action]")]
public void Remove(string UploadFiles)
{
    try
    {
        var filename = UploadFiles;
        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;
    }
}


2 Replies 1 reply marked as answer

UD UdhayaKumar Duraisamy Syncfusion Team August 16, 2022 04:34 PM UTC

Hi Mason,


We are validating the requirement. We will update the further details in two business days (18th August 2022).


Regards,

Udhaya Kumar D



UD UdhayaKumar Duraisamy Syncfusion Team August 17, 2022 08:29 AM UTC

Hi Mason,


We have created a simple working sample based on the shared code snippet and attached the sample below for your reference.


Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/FileUploadSample307649693


@page "/"

 

<h1>Blazor FileUploader</h1>

<SfUploader ID="UploadFiles"

            AllowMultiple=false>

    <UploaderAsyncSettings SaveUrl="api/SampleData/Save"

RemoveUrl="api/SampleData/Remove/">

    </UploaderAsyncSettings>

    <UploaderEvents BeforeRemove="@BeforeRemove"></UploaderEvents>

</SfUploader>

 

@code {

 

    public static void BeforeRemove(BeforeRemoveEventArgs beforeRemoveEventArgs)

    {

        beforeRemoveEventArgs.PostRawFile = false;

    }

}

[HttpPost("[action]")]

        public void Remove(string UploadFiles)

        {

            try

            {

                var fileName = UploadFiles;

                var filePath = Path.Combine(hostingEnv.WebRootPath);

                var fileSavePath = filePath + "\\" + fileName;

                if (System.IO.File.Exists(fileSavePath))

                {

                    System.IO.File.Delete(fileSavePath);

                }

            }

            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;

            }

        }


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D


Marked as answer
Loader.
Up arrow icon