FileGetMimeType

Gets the MIME type for the file path/file object you have specified.

Method Signature

FileGetMimeType(file=[string], strict=[boolean])

Arguments

Argument
Type
Required
Description
Default

file

string

true

The file path or file object to get the MIME type for.

strict

boolean

false

If true, throws an exception if the file does not exist or is empty. If false, returns "application/octet-stream" for non-existent or empty files.

true

Examples

Two PDFs and two text files with and without strict mode

Assume that you have a file named test.pdf in temp directory and test.txt in the same folder, and you want to check the MIME type. Here test.txt is a copy of test.pdf with extension renamed to txt.

<bx:script>
	mimeTypes = "";
	mimeTypes = listAppend( mimeTypes, fileGetMimeType( expandPath( "/folder1/test.pdf" ) ) );
	mimeTypes = listAppend( mimeTypes, fileGetMimeType( expandPath( "/folder1/test.pdf" ), false ) );
	mimeTypes = listAppend( mimeTypes, fileGetMimeType( expandPath( "/folder1/test.txt" ) ) );
	mimeTypes = listAppend( mimeTypes, fileGetMimeType( expandPath( "/folder1/test.txt" ), false ) );
	writeOutput( mimeTypes );
</bx:script>

Result: application/pdf,application/pdf,text/plain,text/plain

Additional Examples

file = filegetmimetype( filepath / filename.EXT );
writeDump( file );

Last updated

Was this helpful?