Gallery
a list for 'against comparison'
Share
Explore
Pipedream

Determine Mime-Type - Audio


import fs from "fs";
import mime from "mime-types";

export default defineComponent({
async run({ steps, $ }) {
// adjust filePath to your own use-case.
const filePath = steps.download_audio_to_tmp.$return_value.filePath;

try {
// Read the downloaded file
const fileBuffer = await fs.promises.readFile(filePath);
const mimeType = mime.lookup(filePath);

// List of known audio MIME types
const audioMimeTypes = [
"audio/mpeg",
"audio/aac",
"audio/ogg",
"audio/wav",
"audio/x-flac",
"audio/mp4",
];

const isAudio = mimeType && audioMimeTypes.includes(mimeType);

return { filePath, fileName: steps.download_audio_to_tmp.$return_value.fileName, mimeType, isAudio };
} catch (error) {
$.export('error', error);
throw new Error(`Failed to detect the MIME type of the file: ${error.message}`);
}
}
});
Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.