Storage: uploadBytes() does not use proper ContentType
- 主要言語
- TypeScript
- スター
- 7.8k
- フォーク
- 2.2k
- 平均マージ
- 22時間 28分
- マージ済み PR(30日)
- 6
説明
### Version info
**Angular:** 13.3.0
**Firebase:** 10.5.0
**AngularFire:** 7.2.1
### How to reproduce these conditions
**Steps to set up and reproduce**
```
import { ref, Storage, uploadBytes } from '@angular/fire/storage';
@Component({
template: ``
})
export class UploadComponent {
constructor(private storage: Storage) {}
async upload(fileInput: any) {
const file: File = fileInput.files[0];
await uploadBytes(ref(this.storage, '/images'), file, { contentType: 'image/png' });
// -> content-type of the POST request is multipart/related instead of image/png and thus firestore security rules fail with 403!
}
}
```
**Sample data and security rules**
```
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if false;
}
match /images/{allPaths=**} {
allow read: true;
allow write: if resource.contentType == 'image/png';
}
}
```
### Debug output
** Errors in the JavaScript console **
```
Firebase Storage: User does not have permission to access 'images/demo.png'. (storage/unauthorized)
```
** Screenshots **

### Expected behavior
File is sucessfully uploaded, with contentType = 'image/png'
### Actual behavior
With enabled security rule, file file fails to upload (when checking network request, the contentType is set to 'multipart/related'. As soon as security rule is disabled (ie allow write: if true;) everything works perfectly.
コントリビューションガイド
調査の方向性
エントリーポイント uploadBytes() から開始し、Angular 13.3.0、Firebase 10.5.0、AngularFire 7.2.1 の例で問題を再現します。生成されたアップロードリクエストと Firebase Storage のメタデータ処理を調査します。リクエストが contentType: 'image/png' を遵守し、指定されたセキュリティルールがアップロードを許可すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- angular, firebase, typescript
- 領域
- cloud
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100