这个问题通常是由于缓存导致的。可以通过添加一个随机查询参数来解决这个问题,确保每次文件路径都是唯一的。以下是一个示例代码:
component.ts文件:
upload() {
// get file and perform upload
this.uploadService.uploadFile(file).subscribe((res: any) => {
// set file path for display
this.filePath = res.filePath;
});
}
generateRandomQueryParameter() {
return Math.floor(Math.random() * Math.pow(10, 20));
}
component.html文件:
在上面的示例中,生成了一个随机数作为查询参数,当每次上传图像时,它会在查询参数中附加生成的随机数,确保每次文件路径都是唯一的,从而避免缓存问题。