Prevent repeated file upload

How can i prevent the user from uploading the same file or programmatically check if the filename already exists. Its an application requirement the filename to be unique. Since im storing the data of the file in a dictionary and using the filename as key.


6 Replies

YS Yohapuja Selvakumaran Syncfusion Team August 1, 2023 09:44 AM UTC

Hi jose,


Thank you for contacting us. We are delighted to inform you that you can restrict the file from uploading if the same file is already uploaded by using the select event with the args.Cancel set to true. We have prepared a sample that specifically addresses your requirement to demonstrate how this can be achieved. Please refer to the attached sample for more information.


Code Snippet

public void SuccessHandler(SuccessEventArgs args)
    {
        uploadedFiles.Add(args.File.Name);
    }
    public void SelectHandler(SelectedEventArgs args)
    {
        string selectedfile = args.FilesData[0].Name;

        if (uploadedFiles!=null && uploadedFiles.Contains(selectedfile))
        {
            args.Cancel = true;
        }
    }

 



Regards,

Yohapuja S




Attachment: FileUpload_Repeat_3c1186ea.zip


Hüseyin November 23, 2023 10:23 AM UTC

Hello,

When we set args.Cancel true, the uploader clears the entire list. Shouldn't it just delete the duplicate file from the list? I am asking for your urgent help on this matter. Thank you from now.



YS Yohapuja Selvakumaran Syncfusion Team December 4, 2023 05:06 PM UTC

Hi Huseyin

We apologize for the delay in getting back to you. In the provided sample, the prevention of uploading duplicate files only ensures that duplicate files are not added to the list. It does not clear the entire list of files. Kindly check out the below gif image.


We kindly request further clarification regarding your concern. To assist you more effectively, could you please provide the following details:

Video Illustration: Could you share a video illustrating the issue you're experiencing? This will help us better understand the scenario and the specific behavior you're encountering.

Scenarios for Entire File Clearing: Please specify the scenarios or conditions in which the entire file list should be cleared. Understanding these specific scenarios will aid us in addressing your issue accurately.


Regards,

Yohapuja S


Attachment: FileUpload_Repeat_3c1186ea_556cca56.zip


JE Jenia March 3, 2024 06:04 PM UTC

Good afternoon, what @huseyin mentions is that it is not working with AutoUpload="true" I am using version 24.2.3.



YS Yohapuja Selvakumaran Syncfusion Team March 19, 2024 02:46 PM UTC

Hi Jenia,

We have considered the reported issue When using auto upload as true and preventing the duplicate file in the select event, the file list is clearedas a bug from our end and the fix for the issue will be included with our upcoming weekly release on March 27th, 2024.

Now you can track the status of the reported issue through the feedback below,

Feedback Link: https://www.syncfusion.com/feedback/51905/when-using-auto-upload-as-true-and-preventing-the-duplicate-file-in-the-select


Disclaimer: “Inclusion of this solution in the weekly release may change due to other factors including but not limited to QA checks and works reprioritization.



Regards,

Yohapuja S



YS Yohapuja Selvakumaran Syncfusion Team April 9, 2024 05:19 AM UTC

Hi Jose,


We have included the fix for the issue When using auto upload as true and preventing the duplicate file in the select event, the file list is cleared " with our package version “25.1.38”. Therefore, we recommend upgrading to our latest version to resolve the current issue. Kindly check out the below upgraded sample.


Rootcause:

The IsShowFileList property was set to false when preventing a file in a selected event, unintentionally hiding the file list. However, this prevented both new and existing files from being visible. To resolve this, the property was removed. Moving forward, it's essential to ensure consistent file list visibility by refining the logic and conducting thorough testing.


Sample: https://blazorplayground.syncfusion.com/hZVJZTXuCFwadKjo


Release Notes: https://blazor.syncfusion.com/documentation/release-notes/25.1.37?type=all#uploader



Regards,

Yohapuja S


Loader.
Up arrow icon