LoginSignup
2
0

More than 1 year has passed since last update.

Cloud Storage for Firebaseのエミュレーターに接続して画像をアップロードしたら失敗した話

Posted at

開発中のAndroidアプリで、ローカルで起動したFirebase Emulator SuiteのCloud Storageに接続するように設定しました。

FirebaseStorage.getInstance().useEmulator("10.0.2.2", 9199)

しかし、通常通り画像のアップロード処理を行なってみたところ次のようなエラーが発生しました。

StorageException has occurred.
	User does not have permission to access this object.
		Code: -13021 HttpResult: 403
            ...
            ...
com.google.firebase.storage.StorageException: User does not have permission to access this object.

調べてみたところ、自動的に読み込まれたstorage.rulesの内容がデフォルトのままになっており、書き込みと読み取りに対するアクセスがすべてfalseに設定されていました。

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if false;
    }
  }
}

なので、一時的にアクセス可能にするためにallow read, write: if true;に書き直しました。

rules_version = '2';
service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write: if true;
    }
  }
}

エミュレーターを再起動して、もう一度アップロード処理を実行したところ問題なくローカルのストレージにファイルがアップロードされました。

このルールを本番環境にデプロイしないでください。正しくルールを設定した上でデプロイすることを心がけましょう。

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