angular / angular/angularfire

Storage: uploadBytes() does not use proper ContentType

未關閉
#3,196 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
TypeScript
星號
7.8k
分支
2.2k
平均合併
22 小時 28 分鐘
30 天內合併 PR
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 **
![grafik](https://user-images.githubusercontent.com/7628757/160568062-7966ea21-4fa4-4042-b6b5-5eda4959e7da.png)

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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。