LoginSignup
0
2

More than 3 years have passed since last update.

Google Cloud Storageで画像操作したメモ

Posted at

画像uploadするにはどうすればいいんだろう
いろいろな記事を参考にしてみた
うまくいかない?
ちょっと!よくよく見るとこの記事、リファレンスに書かれてるものとオプション名違ってるじゃん!そりゃ期待通り動かないよ!
ってことがあったので、メモっておきます。

前提

upload

const {Storage} = require('@google-cloud/storage');
const storage = new Storage({
    projectId: 'hogehoge-project',
    keyFilename: './serviceAccountKey.json', // 前提で取得済みのキーファイル
});

const BUCKET_NAME = 'hogehoge-project.appspot.com';

storage
.bucket(BUCKET_NAME)
.upload('./image.png' /* uploadしたいファイル */, { destination: 'uploaded_image.png' /* storageにこのファイル名でuploadされる */ })
.then(() => { /* success */ })
.catch((err) => { /* error */ });

delete

storage
.bucket(BUCKET_NAME)
.file('uploaded_image.png')
.delete()
.then(() => { /* success */ })
.catch((err) => { /* error */ });

リファレンス

バケットの操作周りをみれば良い
https://googleapis.dev/nodejs/storage/latest/Bucket.html

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2