javascript - 无法从文件名中探测 mimetype
问题描述
我正在从 azure 读取文件。并且 mimetypevideo/mp4
在response.headers["content-type"]
. 我找不到如何将 mimetypes 添加到文件,因为我收到以下错误
无法从文件名探测 mimetype
axios({
method: "get",
url: "https://stemuli.blob.core.windows.net/stemuli/mentor-lesson-video-c20665e2-b17c-4f22-9ef8-f6cd62b113dd.mp4",
responseType: "stream"
}).then(function (response) {
const videoType = response.headers["content-type"].split("/")[1];
const file = fs.createWriteStream(
`./cache/thumbnails/${tempFileName + "."}${videoType}`
);
response.data.pipe(file);
thumbsupply
.generateThumbnail(`./cache/thumbnails/${tempFileName}`)
.then(thumb => res.json(thumb))
.catch(err => {
res.json({
Error: "Error creating thumbnail for video"
});
console.log(err);
});
});
解决方案
您收到的错误来自在线的 thumbsupply 包:
thumbsupply
.generateThumbnail(`./cache/thumbnails/${tempFileName}`)
您可以在他们的代码中看到错误消息:
_fetchThumbnailSupplier(file, options) {
const mime = options.mimetype || mimetypes.lookup(file);
let Supplier;
if (!mime) {
throw new E.UnknownFiletypeError(file, undefined, "Unable to probe mimetype from filename");
}
因此,您只需传入 mimetype 选项即可更正您的代码:
thumbsupply
.generateThumbnail(`./cache/thumbnails/${tempFileName}`,
{ mimetype: response.headers["content-type"] } )
推荐阅读
- python - 如何根据numpy矩阵中的值获取列、行号
- javascript - Javascript 中的时间到秒和秒到时间
- php - SQL 查询 - 选择计数时返回 0(*)
- java - Java Stream 计数操作直到整数变为 0
- java - 如何使用java检查Oracle程序是否正确创建?
- c++ - C++ 排序双向链表:在列表中间插入问题
- python-3.x - scipy.stats - 获取对数正态的基础 mu 和 sigma
- c# - 如何避免线程应用程序中的全局变量
- jenkins - httpRequest 之后的函数行不在 groovy jenkins 管道中执行
- python - Python线程内存泄漏