1
gcloud-node를 사용하여 노드 가져 오기를 사용하여 Google Cloud Storage의 버킷으로 가져온 파일을 업로드하는 코드를 작성하고 있습니다. .node.js를 사용하여 Google Cloud Storage에 업로드되는 파일의 Content-Type을 설정하는 방법
지금까지 모든 작업이 완료되었지만 GCloud에서 파일에 대해 Content-Type
을 설정하는 방법을 찾는 데 문제가 있습니다. 그렇지 않으면 파일이 application/octet-stream
으로 다운로드됩니다.
function saveImage(response, destFile) {
return new Promise((resolve, reject) => {
if (response.status !== 200) {
reject(new Error('Bad Response'));
}
// How do I set this on the file uploaded to the bucket?
const contentType = response.headers.get('Content-Type');
try {
const file = bucket.file(destFile);
const writeStream = file.createWriteStream();
writeStream.on('error', err => {
reject(err);
});
writeStream.on('finish',() => {
resolve(getPublicUrl(destFile));
});
response.body.pipe(writeStream);
} catch (e) {
reject(e);
}
});
}