在Angular 6应用程序中,我使用Cache API来存储和删除MP3文件。
在Safari中,当尝试删除文件时,它不会被删除,而且我会收到一个" Quota Exceeded"错误消息(在Chrome中效果很好)。
我创建了一个Example Angular Firebase App,以便您可以看到问题。
重现问题的步骤:
任何人都可以帮我看看我的代码有什么问题吗?
我调用删除文件的方法是 removeFile()
app.component.ts
import { Component, OnInit } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
// Omitted ...
saveFile() {
this.resetValues();
caches.open(this.id).then((cache) => {
console.log("open complete", cache);
return fetch(this.url).then((response) => {
console.log("fetch complete", response);
return cache.put(this.url, response).then((data) => {
console.log("cache complete", data)
this.status = 'File saved';
});
})
}).catch((error: Error) => {
this.errorMessage = error.message;
console.error('Error caching file!', error);
});
}
removeFile() {
this.resetValues();
caches.delete(this.id).then((cacheDeleted) => {
console.log("File removed from cache:", cacheDeleted);
this.status = 'File removed';
}).catch((error: Error) => {
this.errorMessage = error.message;
console.error('Error removing file from cache :(', error);
});
}
}
的package.json
{
// Omitted ...
"dependencies": {
"@angular/animations": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.0",
"@angular-devkit/build-angular": "~0.6.1",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.1",
"@angular/language-service": "^6.0.0",
// Omitted ...
}
}