How to check if file exists in Storage Bucket before uploading a new file

In this article we will cover some scenarios that we encounter while dealing with file picker control and Storage buckets in UiPath Apps.

  1. How to check whether file exists in the Storage bucket.
  2. How to upload unique file name or the original file name in the Storage bucket.
    This is the App that we built for this example.We will not go through the designing part of the process.

Lets see the integration now.

Step 1:- We will first click on the Check file in Storage Bucket, go to General tab and then bind the value to the variable var_Check_File_inBucket and set the value to True for Default.

Step 2:- Now, we will click on Upload file with Unique Name, go to General tab and then bind the value to the variable var_IsTimeStamp.


Then we will click on Events tab and create a rule.

Step 3:- Now, we will configure the rule and set the value of the file name to the variable varGeneratedFileName

We have used the concat function to create the file name.

FilePicker_Upload_File.fileNameWithoutType- This will give the file name without extension.

FilePicker_Upload_File.fileType- This will give the file type eg- pdf, xls,xlsx etc.

if(var_IsTimeStamp,Concat(“-”,Guid()),””),FilePicker_Upload_File.fileType)- This means if “Upload with Unique File Name” is checked by the user , then it will contact GUID (unique number) with the file name else it will blank.


Step 4:- We will now click on File Picker control and under File added click a new rule.


Step 5:- We will again configure the same rule and add a file name to the variable varGeneratedFileName

We will use If /else condition here which would check if the Check file in Storage bucket is enabled i.e True and Upload with Unique Name is disabled i.e False

If the above condition is met, then we will get the file from the Storage bucket and assign it to a variable var_File_from_Bucket

When completed , we will show the File Replacement warning.

Step 6:- We will now click on Update button & create a rule.

We will configure the rule & use Upload file to Storage Bucket.

Step 7:- Once the file will be uploaded to Storage Bucket, we will set the store the generate file name to a variable Uploaded File Name


Lastly , we will bind the value of the text area to a variable varStatusMessage.

Output-

Scenerio-1 :- Check file in Storage Bucket is enabled , we will drop a file to upload in Storage bucket.

As the file was already there in the Stoarage bucket , so app will display a File Replacement Warning.


Now, at this moment , we have 3 options-

  1. We can click on Upload button to upload a file that already exists.
  2. We can click on trash icon to delete the file.
  3. We can click on Upload with Unique name

Scenerio-2 :- Check file in Storage Bucket is disabled and Upload will Unique Name is enabled.


Again we will have 3 optiosn here-

  1. We can click on Upload button to upload the unique file name.
  2. We can click on trash icon to delete the file.
  3. We can click on check file in Storage bucket.

Scenerio-3 :- Check file in Storage Bucket is enabled and Upload will Unique Name is enabled.


I hope you enjoyed the article!

Happy Automation!!!

1 Like

Awesome…

Thanks for sharing…

Regards,
NaNi

1 Like