How to Change the Mime Type of a File from the Terminal

How to set the mime-type of a new created file to application/json? C++

file command try to guess the type of your file by reading it.

And read your file again: it is a plain text file. There is only a simple object stored, nothing that can lead to the application answer.

So without changing your file data, there is nothing you can do from your code to change file command answer.

How can I find out a file's MIME type (Content-Type)?

Use file. Examples:

> file --mime-type image.png
image.png: image/png

> file -b --mime-type image.png
image/png

> file -i FILE_NAME
image.png: image/png; charset=binary

How can I find out a files “mime-type(Content-Type?)”? on Windows

Use File from source or you can get win32 binaries from here

Example from empty file:

COPY NUL >test.ext && "C:\Program Files (x86)\GnuWin32\bin\file" −-mime-type test.ext

Which will return this:

test.ext; text/plain

Update:

Also -b or --brief do not prepend filenames to output lines

file -b −-mime-type test.ext return only the mime-type: text/plain

Type file --help for more options

Note: The sources are much more recent than the executable file kindly made available to us by GnuWin32.

Bash file --mime-type command is not working in Perl Script

$filename is just the filename, it doesn't include the directory portion. So file is looking for the file in your working directory, not the directory in $a.

You need to concatenate the directory name and filename to get a full pathname. Also, you should give a list of arguments to system(), since you're not using shell parsing.

system('file',  '--mime-type', "$a/$fileName");


Related Topics



Leave a reply



Submit