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
Passing Associative Array as Argument with Bash
Executing Script on Receiving Incoming Connection with Xinetd
Redirect Stderr and Stdout to Separate Files in Bash
How to Signal Handler to Survive After "Exec"
What Is the Linux Built-In Driver Load Order
Docker Alpine Executable Binary Not Found Even If in Path
Clean Server Infected with C3284D Virus, Using Search and Replace
How to Download PHP Script from a Web Page with Wget
Create .So Files on Linux Without Using Pic (Position Independent Code) (X86 32Bit)
How to Get Time Since File Was Last Modified in Seconds with Bash
Position of a String Within a String Using Linux Shell Script
Sed: -I May Not Be Used with Stdin on MAC Os X
Assembly: Read Integer from Stdin, Increment It and Print to Stdout
Replace String in a File with Value from Another File
Assembler Systime Giving Error on Executing
Sed to Insert on First Match Only