You would generally want to use a filename that is unique, and which relates to the user (maybe by including their ID in the filename). That means you would pick a filename based on your needs, which likely include making filenames predictable. Whether it makes sense to store the original name as well depends on what you and the client might want to do with the image in the future. Offhand, I can't think of a good reason.
Whether or not you save the original file name would depend on the use case, wouldn't it? For example, if the files were images of receipts that the user is submitting for reimbursement, I would think you'd want to keep the original file name so that the user can later review what has been uploaded and see if there are any receipts on their local machine that have yet to be uploaded. On the other hand, I'm sure there are use cases where keeping the original file name doesn't provide any value for the user.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
Also, I wouldn't generally recommend storing files in a database. The filesystem is made for that, and if all the metadata is in the DB, you can get at the data required for accessing the file just as easily.
Quite right. I had a project that had 100's of thousands of images and we stored the file name and path in the db, but kept the files in the file system. Retrieval was actually faster than using BLOBS.
Tim Moores wrote:Also, I wouldn't generally recommend storing files in a database. The filesystem is made for that, and if all the metadata is in the DB, you can get at the data required for accessing the file just as easily.
Junilu Lacar wrote:Whether or not you save the original file name would depend on the use case, wouldn't it?
Sometimes I suspect that looking for "best practices" interferes with the normal process of requirements gathering. Don't get me wrong, I'm sure that "best practices" can be useful; it's just that it refers more to general concepts than to specific questions like this one.
Here's an example that I'm familiar with: Nowadays I don't go in to visit my financial advisor. When there is a form to be signed, the secretary fills it in and posts it online for me. I download it, print it, sign it, scan it, and upload it. So when the form gets the uploaded form they can see that I named the form "image1.pdf", which is what the scanning software called it. So in this case, no, they don't need to store the filename from my computer. Other companies, as Junilu says, may have different requirements.
(At one time I did work on a system where we uploaded company logos and used them in our website. I'm sure we had no use for the filename from the client system.)
John Knox wrote:Do we need to save the file name as best practice or it is not needed???
It does depend to most extent on the use case(s), one of which could be if client says: "No, we uploaded file only once", but you have an evidence in database, that filename logo.png was uploaded twice by the same client id, hence got overridden...
Thousands of reasons you'd want to store filename, and the same amount of reasons you wouldn't ever need it.