我在我的项目中使用了 Angular、Ionic 和 Firebase。我使用 Uploadcare 将照片上传和检索到应用程序。我可以删除数据库中的文件,但问题是实际图像仍上传到 UploadCare 存储中。
这是我的代码:
organization.service.ts - 这是我在 Firebase 和 UploadCare 中连接应用程序的地方
我得到的回应:
更新
网络响应:
组织服务.ts
deleteOrg(orgId: string){
return this.http
.delete(`https://db-student-portal-default-rtdb.firebaseio.com/add-organization/${orgId}.json`)
.pipe(switchMap(() => {
return this.allOrg;
}),
take(1),
tap(orgs => {
this.organization.next(orgs.filter(o => o.id !== orgId))
})
);
}
//This is the function to delete the image in UploadCare
deleteImage(image: any){
let httpHeader = new HttpHeaders();
httpHeader.set('Authorization', `Uploadcare.Simple ${PUB_KEY}:${SEC_KEY}`);
httpHeader.set('Accept', 'application/vnd.uploadcare-v0.5+json');
this.http.delete(`https://api.uploadcare.com/files/${image}/`, {headers: httpHeader});
}
组织页面.ts
onDeleteOrg(){
this.alertCtrl.create({
header: 'Delete ' + this.loadedOrg.orgName,
message: 'Do you want to delete this organization?',
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'Delete',
handler: () => {
this.loadingCtrl.create({
message: 'Deleting Organization: ' + this.loadedOrg.orgName,
spinner: 'circular'
}).then(loadEl => {
loadEl.present();
//THIS IS WHERE THE DELETION HAPPEN (in the Firebase)
this.orgService.deleteOrg(this.loadedOrg.id).subscribe(() => {
//THIS IS WHERE THE DELETION HAPPEN (in the UploadCare)
this.orgService.deleteImage(this.loadedOrg.imageUrl.replace('https://ucarecdn.com/', ''));
loadEl.dismiss();
this.router.navigate(['/homepage']);
});
});
}
}]
}).then(alertEl => {
alertEl.present();
});
}