如何将图像下载到本地存储? [英] How to download image into local storage?

查看:84
本文介绍了如何将图像下载到本地存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js Firebase Cloud Function,但是需要获取我存储在Firebase Storage中的图像,以便可以发送到Google Cloud vision API.

I am use Node.js Firebase Cloud Function but need get image I have store in Firebase Storage so I can send to Google Cloud vision API.

需要视觉API 从本地图像发送文件:

Vision API require send from local image file:

// const fileName = 'Local image file, e.g. /path/to/image.png';
// Performs safe search detection on the local file
const [result] = await client.safeSearchDetection(fileName);
const detections = result.safeSearchAnnotation;

如何将远程映像下载到本地存储中?

How to download remote image into local storage?

例如,我想将此图像存储在本地存储中:

For example I want store this image in local storage:

  const image = await axios.get(imgUrl)
  

推荐答案

为什么不保存到文件系统

Why don't you save to filesystem https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback , remember the name to get later. Something like:

const image = await axios.get(imgUrl);
const path = '/home/some/path/somefilename.jpg'
fs.writeFile(path, image, function(err, data) {
    if (err) {
        throw (err);
    }
    // save filepath to wherever for later.
    
});

这篇关于如何将图像下载到本地存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆