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

How to pass custom value to preloaded files

Hello,

I have stored uploaded files in the database, with columns: GUID, Name, Size.
The name of the file is not unique. How can I perform remove action with GUID?

Files are prepared from controller with List<UploaderUploadedFiles>, but there is no suitable property to store GUID and pass it to the client side.

I need to call something similar to /RemoveFile?fileId=GUID to delete uploaded file.



9 Replies

DR Deepak Ramakrishnan Syncfusion Team April 7, 2023 04:14 PM UTC

Hi Jiri,


Greetings ……!



Yes we can send additional parameters using ‘Uploading’ event arguments of the File uploader component , And then receive it in server . Please refer to the below documentation for reference.


https://ej2.syncfusion.com/aspnetmvc/documentation/uploader/how-to/add-additional-data-on-upload?cs-save-lang=1&cs-lang=razor


Thanks,

Deepak R.



JI Jirí April 10, 2023 05:51 AM UTC

Hi, thank you for your reply, but I need to pass custom value from server side to the client.

You describe this scenario in links below, but I don't see any way there, how I can pass custom value (database GUID in my case).

https://ej2.syncfusion.com/aspnetmvc/Uploader/PreloadFiles#/bootstrap5

https://ej2.syncfusion.com/aspnetmvc/documentation/uploader/async#preload-files



JI Jirí April 13, 2023 05:25 PM UTC

Hi, do you have some solution for my issue? I read documentation but I can't find nothing. Thank you. 



DO David Oliver April 19, 2023 07:16 PM UTC

In order to call the remove action using a Guid parameter, you will need to use the Guid.Parse() method to convert the Guid string to a Guid object. Then you can use the Remove() method to remove the item with the specified Guid from the collection.


Here is an example code snippet that demonstrates how to call the remove action with a Guid parameter:


java

Copy code

// Assume the following list of items with GUIDs

List<Item> items = new List<Item>()

{

    new Item { Id = Guid.NewGuid(), Name = "Item 1" },

    new Item { Id = Guid.NewGuid(), Name = "Item 2" },

    new Item { Id = Guid.NewGuid(), Name = "Item 3" },

};


// Assume we want to remove the item with this GUID

string guidString = "a7595ee5-96ce-4fc1-a2fc-4e4c4ba4e0b7";


// Parse the GUID string to a Guid object

Guid guidToRemove = Guid.Parse(guidString);


// Call the remove action using the Guid parameter

items.Remove(items.FirstOrDefault(i => i.Id == guidToRemove));

In this example, we first define a list of Item objects with unique Guid identifiers. We then define a string variable that represents the Guid of the item we want to remove. We use the Guid.Parse() method to convert the string to a Guid object. Finally, we call the Remove() method using the FirstOrDefault() method to find the first item in the list that matches the Guid we want to remove.








JI Jirí replied to David Oliver April 19, 2023 08:12 PM UTC

Hi, thank you for your reply, but you probably don't read my question thoroughly. My question is not about removing items from colletion. I want to know, how to pass custom value to preloaded files in the uploader component (guid in my case).



JI Jirí replied to Deepak Ramakrishnan April 26, 2023 12:31 PM UTC

Hi, can I ask you for answer? It's possible to solve my issue or not. If not, do you plan add suport for that?

Thank you.



SP Sureshkumar P Syncfusion Team May 8, 2023 10:17 AM UTC

Jirí, we cannot send the additional data to the preload files because preload files property has only the Name, Size, and Type properties.

To know more about the preload files property, please refer to the documentation: https://help.syncfusion.com/cr/aspnetmvc-js2/Syncfusion.EJ2.Inputs.UploaderUploadedFiles.html



JI Jirí replied to Sureshkumar P May 9, 2023 06:13 AM UTC

Hi, yes I read this part of documentation, so it was the reason to create this thread. I hoped that you have some workaround to this, because saving data to database, where name of file is not unique is common thing. So now is impossible to preload this data back to component, what is a little annoying. I think & hope that it could be useful feature for some next component update.



PK Priyanka Karthikeyan Syncfusion Team May 24, 2023 10:59 AM UTC

Hi Jiri,

Upon reviewing your request, we would like to inform you that Uploader pre-uploaded files are specifically intended for display purposes within the user interface (UI). However, we regret to inform you that we are unable to provide additional data for pre-uploaded files. Additionally, the server call functionality is not available for pre-uploaded files. We apologize for any inconvenience this may cause.

Regards,

Priyanka K



Loader.
Live Chat Icon For mobile
Up arrow icon