qie.base64DetectMimeType¶
Signature: qie.base64DetectMimeType(input)
Returns: String mimeType - the detected mime type
Detects the mime type of the Base64 encoded or byte array input value.
Note
Detection is a guess done by looking for special 'magic' patterns of bytes near the beginning of the bytes. This may be helpful when the mime type is unknown.
Note
Mime types are returned in the type/subtype format. For example: 'application/pdf' or 'text/plain' etc.
Parameters¶
| Type | Name | Description | Default |
|---|---|---|---|
| String or byte[] | input | the Base64 encoded string or byte array to detect |
Example¶
// Example: input as String (Base64 encoded PDF)
var verySimpleBase64PDF = 'JVBERi0xLjQKMSAwIG9iamVjdAp8fCBUeXBlIC9DYXRhbG9nIC9QYWdlcyAyIDAgUgoKMiAwIG9iamVjdAp8fCBUeXBlIC9QYWdlcyAvQ291bnQgMSAvS2lkcyBbMyAwIFIiCk5lb2VtYmVyCmVuZG9iaiAKMyAwIG9iamVjdAp8fCBUeXBlIC9QYWdlIC9QYXJlbnQgMiAwIFIgL1Jlc291cmNlcyA8PgogQ29udGVudHMgNCAwIG9iamVjdAp8fCBMZW5ndGggNDQgfH0Kc3RyZWFtCkIgL0YxIDI0IFRmCjEwMCA3MDAgVGRvcAoKICgpIFh1CkVUIgpzdHJlYW0gZW5kb2JqCgptZApodHJh';
var detectedMimeType = qie.base64DetectMimeType(verySimpleBase64PDF);
// detectedMimeType = application/pdf
// Example: input as String (Base64 encoded text)
var verySimpleBase64HelloWorld = qie.base64Encode('Hello World!');
detectedMimeType = qie.base64DetectMimeType(verySimpleBase64HelloWorld);
// detectedMimeType = text/plain
// Example: input as byte[] (raw PNG bytes)
var verySimpleBase64PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAwAB/4Z1BR8AAAAASUVORK5CYII=';
var pngBytes = qie.base64DecodeToBytes(verySimpleBase64PNG);
detectedMimeType = qie.base64DetectMimeType(pngBytes);
// detectedMimeType = image/png