Tracking unique file names for download purpose

I have a download button in the UI, user clicks on it and download 3 files in a zip format.

It’s not necessary that the files are already there(on the server) when download button is clicked because the backend process can take sometime(30mins to 1 hr) to put the files at a particular location on the server.

Files are going to be in following format in a particular user specific directory.

file1.csv
file2.csv 
file3.csv

I am planning to disable the Download button until the files are uploaded to the particular directory on the server by the backend process.

My goal is to get the latest files from the location for a particular user. In order to get the latest file I was thinking about following approaches :

  1. Generate a UUID/OR an incrementing integer in the UI using Javascript. Send this UUID to the webservice which is responsible for uploading the file to the server. The file will look like this
file1_UUID.csv
file2_UUID.csv
file3_UUID.csv

As soon as Download button is clicked, I am also planning to store the UUID or incrementing integer and username in a database table so that from the UI, using Javascript, I can keep on checking regularly using a webservice whether file corresponding to the latest UUID/incrementing integer exists on the server or not.

  1. Generate UUID/OR Incrementing integer on the back end side (Java webservice side) and then keep on checking regularly using a webservice whether file corresponding to the latest UUID/incrementing integer exists on the server or not.

Questions:

  1. Is creating a table and storing UUID , username etc in a table a good approach?

  2. OR Is generating UUID/Incrementing integer on the webservice a better option rather than generating it on UI side?

  3. Should I really use UUID or an incrementing integer is fine?

Please let me know if I can answer more questions. thanks !

Some of the discussion started in this post but I created a new post since it’s a new question

  1. Sure, you are essentially building a queue system using the database table. I find no fault with that approach. It is actually not bad considering that the queue would even last through a server restart or something.

  2. I would certainly be generating any UUID and integers on the server side in this equation. During the initial click, you send the files they want to the webservice and there you tack on the UUID and integer and keep track of it from there. Any kind of unique IDs that may identify some kind of resource would be best kept out of the hands of the user to prevent any tampering. Plus you might not want the user to know what that UUID is if it is going to be part of a filename that they might target later.

  3. Honestly I would go with UUID over an integer just to help make it more obscure and more unique. Again I wouldn’t want the user to be able to simply guess the filename on the server until I am ready to give it to them. With an integer they might be able to say “Oh perhaps the file is file4.csv” and try to access it directly.

Which brings up another tip, I would try and keep those files out of the web root so they can’t be possibly browsed too and instead have to be fetched explicitly by you. Most server side languages can navigate outside of the webroot if instructed to.

:slight_smile:

2 Likes

Appreciate spending time and providing valuable inputs on my issue. I will certainly go with generating UUID approach on the backend side (I mean on Java side) and then insert it into the table. So, basically, I will be following the flow as I drew in the piece of paper (shown in the screenshot below):

At Step #3 I am doing two things:

  1. Calling the stored procedure
  2. Generating the UUID and inserting it into the table.

Please find few questions:

  1. Since with each Download button click, I am going to have a UUID stored into the database table and my Java web service will generate the files with the UUID appended to the file names like the following :

file1_UUID.csv
file2_UUID.csv
file3_UUID.csv

How should I go about checking the existence of the above files from the UI. Is the following approach okay?

1.1) I’ll write a web service to get the latest UUID from the table.
1.2) I will keep on checking from the UI using setInterval() of Javascript whether file1_UUID exists in a particular location or not. Similarly for files 2 and 3 as well.

So, does the above approach of writing a webservice and calling it at regular interval sounds like a good approach? The reason I am wondering is because UI won’t know about the latest UUID until and unless it queries the database table through a webservice for the most recently generated UUID.

  1. Is having a very long UUID attached to a file name a good idea? Just wondering if such type of file names would look weird ?

Please share your views on this. Thanks !

Thanks for your tip on this. I am storing my files on RHEL server at the following directory srv/file_users/User1

For different users, there will be different folders inside file_users directory. For example, User2,User2. In reality, I will put their name over there. How does this approach sounds? Thanks again !

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.