やりたいこと
ある文字列のQRコードを作って、ストレージ上に配置する。
定義と実際に置く
const QRCode = require('qrcode');
const {Storage} = require('@google-cloud/storage');
const bucketName = 'bucket_name';
const storage = new Storage();
const bucket = storage.bucket(bucketName);
var filename ='shashin.png';
var filepath = path.join(os.tmpdir(), filename);
console.log(filepath);
await QRCode.toFile(filepath, 'QRにしたい文字列');
await storage
.bucket(bucketName)
.upload(filepath, {gzip: false})
.then(res => {
console.log(res[0].metadata);
console.log(`${filename} uploaded to ${bucketName}.`);
})
.catch(err => {
console.error('ERROR:', err);
});