Storage: uploadBytes() does not use proper ContentType
- Linguagem predominante
- TypeScript
- Estrelas
- 7.8k
- Forks
- 2.2k
- Merge médio
- 22h 28min
- PRs com merge (30d)
- 6
Descrição
### 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.
Guia de contribuição
Direção de pesquisa
Comece pelo ponto de entrada uploadBytes() e reproduza o problema com o exemplo usando Angular 13.3.0, Firebase 10.5.0 e AngularFire 7.2.1. Inspecione a solicitação de upload gerada e o tratamento de metadados do Firebase Storage; considera-se concluído quando a solicitação respeita contentType: 'image/png' e a regra de segurança fornecida permite o upload.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- angular, firebase, typescript
- Domínio
- cloud
- Tipo de issue
- Bug
- Dificuldade
- 3/5
- Tempo estimado
- 1-2 dias
- Status de atividade
- Estagnada
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 35/100