How to download image into local storage?

时光毁灭记忆、已成空白 提交于 2020-12-15 04:57:09

问题


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.

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)
  

回答1:


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.
    
});


来源:https://stackoverflow.com/questions/64969703/how-to-download-image-into-local-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!