0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloud Storageで既存オブジェクトを上書きするときは削除権限も必要

0
Last updated at Posted at 2025-11-27

発生した問題

以下のようなコードで file.save() を実行した際、ファイルが既に存在する場合にエラーになりました。

const content = "Hello, World!";
const storage = new Storage(storageOptions);
const bucket = storage.bucket("my-bucket");
const file = bucket.file("path/to/my-file.txt");
await file.save(Buffer.from(content, "utf-8"), {
  contentType: "text/plain",
});

原因

Cloud Storage に適用される IAM 権限  |  Google Cloud Documentation を確認すると以下の記述がありました。

注: 既存のオブジェクトを置換するには、storage.objects.create と storage.objects.delete の両方の権限が必要です。

どうやら上書きは、「削除」→「作成」のような考え方のようで、createとdelete両方の権限が必要とのことです。
ちなみにupdate権限は存在しません。

結論

既存オブジェクトの置換には storage.objects.createstorage.objects.delete の両方が必要です。

該当のサービスアカウントに storage.objects.delete を追加したところ解決しました。

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?