RemoveUrl not working

Hi Syncfusion

Im making a form with a uploader. It's working, and uploading the images.

<SfUploader ID="UploadFiles" AutoUpload=false>
<UploaderAsyncSettings SaveUrl="api/File/Save" RemoveUrl="api/File/Remove">
</UploaderAsyncSettings>
</SfUploader>


and the remove endpoint is taken from one of your samples

[HttpPost("[action]")]
public void Remove(string filename) // Delete the uploaded file here
{
if(filename != null)
{
var filePath = Path.Combine(uploads, filename);
if (System.IO.File.Exists(filePath))
{
//Delete the file from server
System.IO.File.Delete(filePath);
}
}
}


The problem is when im trying to remove the image. Then I get a 400 bad request with this preview

{

    "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",

    "title": "One or more validation errors occurred.",

    "status": 400,

    "traceId": " … “,

    "errors": {

        "filename": [

            "The filename field is required."

        ]

    }

}



If I send the the filename as a parameter in postman its working fine.

Hope you can help

Regards Jakob


1 Reply

KP Kokila Poovendran Syncfusion Team July 29, 2024 05:44 AM UTC

Hi jakob,


Thank you for reaching out to us. We apologize for any inconvenience caused. We have reviewed the issue you reported with the RemoveUrl endpoint in the SfUploader component.

Based on the code snippet you shared, we have created a sample to replicate the issue, but we were unable to do so at our end. Here is the sample code we used:


<SfUploader ID="UploadFiles"

            SequentialUpload=true

            AllowMultiple=true

            >

    <UploaderAsyncSettings SaveUrl="api/SampleData/Save" RemoveUrl="api/SampleData/Remove" />

</SfUploader>


        [HttpPost("[action]")]

        public void Remove(string UploadFiles) // Delete the uploaded file here

        {

            if (UploadFiles != null)

            {

                var filePath = Path.Combine(uploads, UploadFiles);

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

                {

                    //Delete the file from server

                    System.IO.File.Delete(filePath);

                }

            }

        }









From the error message you provided, it appears that the filename parameter is not being correctly sent to the Remove method, resulting in a "400 Bad Request" error due to the missing filename field. To resolve this, ensure that the parameter name in the controller method matches the name used in the request. Here is the adjusted sample above.

Please ensure that the parameter name UploadFiles in the Remove method matches the parameter name expected by the SfUploader component.


If you continue to experience the issue, kindly share a sample project with us, and we will be happy to provide a more precise solution.


Thank you for your understanding and cooperation.


Attachment: BlazorUploadAndDownload_16f5f14.zip

Loader.
Up arrow icon