Storage: uploadBytes() does not use proper ContentType
- 主要语言
- 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 **

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