Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL: Saving MIME-Type or Extension?

Tags:

c#

file

sql

blob

What's the best way to store information about a BLOB in the DB? The File-Extension (.txt, .rar) or the MIME-Type?

Also, what's better: Store the Filename with or without extension ("file" or "file.txt")?

What I'm primarily talking about is a Desktop-App, not a Web-Application.

like image 968
SeToY Avatar asked May 11 '12 07:05

SeToY


People also ask

Is MIME type same as extension?

Whereas file extensions are commonly used for your OS to decide what program to open a file with, Mime types are used by your browser to decide how to present some data (or the server on how to interpret received data). Both are optional but it's a good practice to have an agreement.

How is MIME type stored?

All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop. org.

What type of file extension is SQL?

A file with . sql extension is a Structured Query Language (SQL) file that contains code to work with relational databases. It is used to write SQL statements for CRUD (Create, Read, Update, and Delete) operations on databases.

What is the extension of MIME file?

MIME (Multipurpose Internet Mail Extensions) is an extension of the original Simple Mail Transport Protocol (SMTP) email protocol. It lets users exchange different kinds of data files, including audio, video, images and application programs, over email.


1 Answers

If we are talking about file upload storage for example I will always store the following fields:

  • File - varbinary(MAX)
  • FileName - nvarchar(255) (including file extension, for example "myfile.txt")
  • FileType - nvarchar(255) (the MIME type)

The MIME type is important if it is a web based application and you want to allow download of the files at some point. Having the MIME type allow you to tell the browser how to best handle the file.

So the direct answer to your question is to save both the MIME type and the Extension. The reason being that you cannot ensure the correct file extension has been supplied so you need the MIME type to identify the file type. But you should store the extension with the filename so as you can provide a valid filename at download time.

like image 86
musefan Avatar answered Sep 30 '22 02:09

musefan