Upload and removing.

Hi, Can you send me a sample in asp.net core Razor Page in which a user can upload and remove a file but the file, when uploaded, should get a unique name for eg (filename + GUID). 

Just implement https://ej2.syncfusion.com/aspnetcore/documentation/uploader/how-to/save-and-remove-action-razor/?no-cache=1 in the sample but always give the file a unique name when uploaded and after uploading if the user presses the delete button it should get removed from the server. 

also if possible, code for normal upload, not chunk upload.

Thank you.



1 Reply

BC Berly Christopher Syncfusion Team May 4, 2020 12:52 PM UTC

Hi Naresh, 
  
Greetings from Syncfusion support.  
  
We can rename the filename in the file selected event and set true for modified data to display the file name with modified name in UI, save action and remove action.  
  
Please find the code example and screenshot from below. 
  
@Html.AntiForgeryToken() 
<div class="upload-wrapper"> 
    <ejs-uploader id="uploadFiles" selected="OnSelect" asyncSettings="@asyncSettings" multiple="false" autoUpload="false" uploading="addTokens" removing="addTokens"></ejs-uploader> 
</div> 
 
<script> 
    function OnSelect(args) { 
        args.filesData[0].name = args.filesData[0].name + getGUID(); // Change the file name with generated GUID 
        args.isModified = true; // Set the modified data as true 
    } 
    function getGUID() { // Generate the GUID 
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { 
            var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); 
            return v.toString(16); 
        }); 
    } 
</script> 

  
Screenshot: 
  
UI: 
  
 
  
Save Action: 
  
 
  
Remove Action: 
  
 
 
  
Please find the sample from the below link. 
  
Regards, 
Berly B.C 


Loader.
Up arrow icon