0

A client of mine came with the following demand:

  • Add the option to upload a file to the server
  • Save the file id as a guid in database

I followed this answer- so the file upload is working(to a specific location on the server) http://stackoverflow.com/questions/5193842/file-upload-asp-net-mvc-3-0

What i don't familiar with is his second demand: Save the file id as a guid in database

  • What does it mean?
  • Why does the file need a guid id in the database?
  • What should I do in extra to the post I linked to?(security check, extension check?)
Eran Meir
  • 923
  • 3
  • 17
  • 32

1 Answers1

1

guid = globaly unique identifier.

Why does a file need a guid in database ? well because its your client's requirement its not required by the database.

And finally how to do it? is simple when you will be saving a filename to database generate a guid and save it to the database you can generate a guid like this Guid id = Guid.NewGuid(); and you can create a separate column in the database for saving file's guids.

Naveed Ahmad
  • 314
  • 6
  • 18
  • Oh so, he just meant the file name to be encrypt? * also, what should i do in extra to this kind of task? security check etc` – Eran Meir Nov 20 '15 at 08:40
  • not encrypted but i guess he wanted them to be unique and not easily guessable. i didn't understand the second part "security check" – Naveed Ahmad Nov 20 '15 at 08:42
  • sorry, i'll try to explain- what else should i do? i know its up to me but what are the "default" things i need to check for(like not allow to upload files that are bigger then 4 mb and specific extensions) – Eran Meir Nov 20 '15 at 08:45
  • one other question - do you think a table like this is enough? columns "Id- int, FileName- guid, uploadDate- datetime" – Eran Meir Nov 20 '15 at 08:47
  • it all depends on the requirements and type of files you are uploading, if you are uploading profile images you should only allow png/jpg you will have to see what your users are and how they are going to use your app and what is needed. – Naveed Ahmad Nov 20 '15 at 11:50