我正在使用量角器。我必须下载一些图像并将其上传到相应的位置,并且每个图像都不同。我为此使用了以下代码
const download = require('image-downloader');
options = {
url: 'https://dbamedia.blob.core.windows.net/files/34f6fbc070754541a8828bb78c6a1e87',
dest: './files'
}
download.image(options).then(({ filename, image }) => {
console.log('File saved to', filename)
}).catch((err) => {
console.error(err)
});
我可以通过此代码下载图像。但是当我检查目标文件夹时,文件名没有扩展名(.jpg、.png)。因此,当我尝试上传这些文件时,出现错误'文件不支持'。如果它下载了文件扩展名,我可以成功上传它。我该如何解决这个问题。提前致谢。
要使用另一个名称保存文件,您需要在dest
属性中添加文件名:
const download = require('image-downloader');
options = {
url: 'https://dbamedia.blob.core.windows.net/files/34f6fbc070754541a8828bb78c6a1e87',
dest: './files/image.jpg' // Save file as image.jpg in the ./files
}
download.image(options).then(({ filename, image }) => {
console.log('File saved to', filename)
}).catch((err) => {
console.error(err)
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句