Error: storage/object-not-found when trying to upload large image file
Error: storage/object-not-found when trying to upload large image file
尝试使用 RxFire 在 Google 云存储中上传大型图像文件时出现错误:storage/object-not-found。
他们说在存储桶中找不到图像,但当我检查时,我看到了它们!
我用小图片(可能是 100kb...)进行了测试,效果很好。
但尝试使用 > 500kb 的图像,不起作用...
upload$
.pipe(
switchMap((event: any) => {
const name = Math.random().toString(36).substring(5);
const blob = event.target.files[0];
const type = blob.type.replace('image/', '');
const ref = storage.ref(`uploads/test/${name}.${type}`);
return put(ref, blob);
}),
map(snapshot => snapshot),
filter(snapshot => snapshot.totalBytes === snapshot.bytesTransferred),
mergeMap(snapshot => getDownloadURL(snapshot.ref))
)
.subscribe(url => {
console.log('Results', url)
}, (error) => {
// ERROR HERE
console.log('error', error)
})
预期结果:上传大图像
实际结果:错误
Uncaught t {code_: "storage/object-not-found", message_: "Firebase .
Storage: Object 'uploads/test/7xpbilmb.jpeg' does not exist.",
serverResponse_: "{↵ "error": {↵ "code": 404,↵ "message":
"Not Found. Could not get object"↵ }↵}", name_: "FirebaseError"}
两种方式都可以。
承诺
storageRef.put(blob, {customMetadata}).then(data => {
data.ref.getDownloadURL().then(url => {
// do whatever you want with url
});
});
观察值
downloadURL = new Subject();
this.downloadURL.pipe(
map(obs => obs),
concatAll()
).subscribe(url => {
// do whatever you want with url
});
let task = ref.put(blob, {customMetadata});
task.snapshotChanges().pipe(
finalize(() => this.downloadURL.next(ref.getDownloadURL()))
).subscribe();
这应该足以让您获得下载 URL。如果您想使用可观察对象跟踪上传进度,请使用以下代码:
task.percentageChanges().subscribe(progress => {
console.log('upload progress: ', progress);
if (res >= 100) {
// HOORAY!
}
});
尝试使用 RxFire 在 Google 云存储中上传大型图像文件时出现错误:storage/object-not-found。
他们说在存储桶中找不到图像,但当我检查时,我看到了它们!
我用小图片(可能是 100kb...)进行了测试,效果很好。
但尝试使用 > 500kb 的图像,不起作用...
upload$
.pipe(
switchMap((event: any) => {
const name = Math.random().toString(36).substring(5);
const blob = event.target.files[0];
const type = blob.type.replace('image/', '');
const ref = storage.ref(`uploads/test/${name}.${type}`);
return put(ref, blob);
}),
map(snapshot => snapshot),
filter(snapshot => snapshot.totalBytes === snapshot.bytesTransferred),
mergeMap(snapshot => getDownloadURL(snapshot.ref))
)
.subscribe(url => {
console.log('Results', url)
}, (error) => {
// ERROR HERE
console.log('error', error)
})
预期结果:上传大图像
实际结果:错误
Uncaught t {code_: "storage/object-not-found", message_: "Firebase .
Storage: Object 'uploads/test/7xpbilmb.jpeg' does not exist.",
serverResponse_: "{↵ "error": {↵ "code": 404,↵ "message":
"Not Found. Could not get object"↵ }↵}", name_: "FirebaseError"}
两种方式都可以。
承诺
storageRef.put(blob, {customMetadata}).then(data => { data.ref.getDownloadURL().then(url => { // do whatever you want with url }); });
观察值
downloadURL = new Subject(); this.downloadURL.pipe( map(obs => obs), concatAll() ).subscribe(url => { // do whatever you want with url }); let task = ref.put(blob, {customMetadata}); task.snapshotChanges().pipe( finalize(() => this.downloadURL.next(ref.getDownloadURL())) ).subscribe();
这应该足以让您获得下载 URL。如果您想使用可观察对象跟踪上传进度,请使用以下代码:
task.percentageChanges().subscribe(progress => {
console.log('upload progress: ', progress);
if (res >= 100) {
// HOORAY!
}
});