0

I have a web application where users can upload office documents. In addition to uploading files users also specify extra information about them that's not contained in the files themselves but is important to the web application. Information such as mydocument.docx is a brochure or a manual, etc.

The files are uploaded immediately upon selection but the other information such as whether or not a particular file is a brochure is only sent to the server later when the user clicks a save button.

So I need a way to sync the information a user submits about a file with the file data even though they're uploaded separately. I first thought of using an MD5 hash of each file's data as a way to link the information, but the performance is terrible and makes it unfeasible.

Another idea I have is to use Math.random plus the filename and the user's ID as a key to connect them. Since Math.random is seeded based on system time it should be unique enough that collisions would be highly unlikely.

Is there a better way to do this that I'm missing? Both of these methods feel a little heavy handed/hacky for what I'm trying to do.

  • 1
    I'd use a GUID. Filenames are not necessarily unique and Math.random might have collision issues, depending on what rounding you use. – Dan Pichelman Apr 6 '16 at 15:50
  • @DanPichelman I don't think javascript supports GUIDs. I've seen js libraries that generate them but I'm not sure if those implementations are any more robust than Math.random. – Legion Apr 6 '16 at 16:00
  • Upload the file, have the server generate the GUID & return it as a string. Include that string with any other updates. – Dan Pichelman Apr 6 '16 at 17:05
  • @DanPichelman That creates the same problem. Since it's plausible that multiple files with the same filename could be uploaded I'd have no way to pair the GUID generated on the server with information on the client side. – Legion Apr 6 '16 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.