嗨,我有问题。当我覆盖现有的blob时,我不能 清除缓存,以便显示以前的blob版本。这带来了一个 用户体验不佳。
显示新blob的最快方式(但也不是即时的)是通过链接 myaccount-secondary.blob.core.windows.net/mycontainer/miblob (The access keys for your storage account are the same for both the primary and secondary endpoints.)
因为我不喜欢这个解决方案...... 然后,尝试先删除blob但继续缓存旧的 斑点。从上传时我需要一些东西来擦除缓存 后端节点。
var express = require('express')
var app = express()
var busboy = require('connect-busboy')
var azure = require('azure-storage')
var nconf = require('nconf');
nconf.env().file({ file: 'config.json', search: true });
var tableName = nconf.get("TABLE_NAME");
var partitionKey = nconf.get("PARTITION_KEY");
var accountName = nconf.get("STORAGE_NAME");
var accountKey = nconf.get("STORAGE_KEY");
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:3000');
res.setHeader('Access-Control-Allow-Methods', 'POST');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
//res.setHeader("Cache-Control", "public, max-age=01");
var _send = res.send;
var sent = false;
res.send = function(data){
if(sent) return;
_send.bind(res)(data);
sent = true;
};
next();
});
app.use(busboy())
app.use(express.static('public'))
app.get('/', function(req, res) {
res.sendFile('index.html')
})
app.post('/upload', function(req, res, params) {
req.pipe(req.busboy);
var name;
req.busboy.on('field', function (fieldname, val) {
name = val+'.jpg';
});
req.busboy.on('file', function(fieldname, file, filename) {
var blobSvc = azure.createBlobService(accountName, accountKey);
file.pipe(blobSvc.createWriteStreamToBlockBlob('images', name, function(error) {
if (!error) {
res.send(200, 'upload succeeded')
} else {
res.send(500, JSON.stringify(error))
}
}))
})
})
app.listen(process.env.PORT || 3201, function() {
console.log('Example app listening on port 3000!')
})
答案 0 :(得分:0)
您的节点代码看起来很好。在我的测试中,如果blob URL保持不变,浏览器将缓存旧版本。因此,即使存储器保持正确的图像,旧图像仍然会出现。我认为你面临同样的问题。
要防止它,您可以在前端尝试以下代码:
<img src="https://youraccount.blob.core.windows.net/mycontainer/miblob?" + Math.random() />
这将确保每个请求都是唯一的,因此您将始终获得最新的图像。
更多相关信息:
Refresh image with a new one at the same url
Why am I seeing an old version of an image? - Clearing Your Browser Cache