我正在使用
我想要实现的目标
将图像上传到firebase(将其关闭)
上传前调整图片大小
我被困的地方
所以我可以成功将图像上传到firebase存储
我想避免的是用户上传大于300 x 300的图片
问题
我的上传服务
以下是我的组件成功上传到firebase的方式。如果有人可以在上传之前协助如何调整大小/缩小图片大小,我将非常感激!
uploadImage(upload: Upload) {
this._subscription = this.authService.user.subscribe(user => {
if (user) {
// Generate a new firebase key
let newPostKey = firebase.database().ref().child('albums').push().key;
// Create a reference to the firebase storage
this.imagePathString = 'thumbnail/' + newPostKey + '/thumbnails';
const storageRef = firebase.storage().ref();
const uploadTask = storageRef.child(this.imagePathString).put(upload.file);
// Upload task initiated - View progress and update real time database
uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED,
(snapshot) => {
upload.progress = (uploadTask.snapshot.bytesTransferred / uploadTask.snapshot.totalBytes) * 100;
console.log(upload.progress);
},
(error) => {
// upload failed
console.log(error)
},
() => {
return undefined;
}
);
}
});
}