이미지를 로컬 저장소에 다운로드하는 방법은 무엇입니까?
Nov 23 2020
Node.js Firebase Cloud Function을 사용하고 있지만 Google Cloud Vision API로 보낼 수 있도록 Firebase 저장소에 저장된 이미지를 가져와야합니다.
Vision API는 로컬 이미지 파일에서 전송 해야 합니다.
// 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;
원격 이미지를 로컬 저장소에 다운로드하는 방법은 무엇입니까?
예를 들어이 이미지를 로컬 저장소에 저장하고 싶습니다.
const image = await axios.get(imgUrl)
답변
1 kg99 Nov 23 2020 at 14:02
파일 시스템에 저장하지 않는 이유 https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback, 나중에 얻을 수 있도록 이름을 기억하십시오. 다음과 같은 것 :
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.
});