覆盖 Azure 存储中的现有 blob 不适用于 NODE
Overwrite an existing blob in Azure storage does not work with NODE
新问题
When I overwrite a blob and then update the browser is still caching
the main image and not the new one. I have read that there is a
cache-control property but I can not implement it. I need to clean the
blob cache that has just been uploaded
老问题
我正在尝试使用 connect-busboy 中间件和以下方法覆盖现有的 blob,但文件没有被覆盖,我不明白为什么。
createBlockBlobFromStream(container, blob, (Stream), streamLength,
options, callback) → {SpeedSummary}
Uploads a block blob from a stream. If the blob already exists on the
service, it will be overwritten.
app.post('/upload', function(req, res, params) {
var name;
req.busboy.on('field', function (fieldname, val) {
name = val+'.jpg';
});
req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
file.on('data', function (data) {
console.log(name);
console.log(data);
var bufferStream = new stream.PassThrough();
bufferStream.end(data);
var blobSvc = azure.createBlobService(accountName, accountKey);
blobSvc.createBlockBlobFromStream('images', name, bufferStream, data.length, function (error, result, response){
if (!error) {
res.send(200,'upload succeeded')
} else {
res.send(500,JSON.stringify(error))
}
})
});
});
});
每 Azure Storage SDK for Node API Reference,
createBlockBlobFromStream(container, blob, (Stream), streamLength,
options, callback) → {SpeedSummary}
Uploads a block blob from a stream. If the blob already exists on the
service, it will be overwritten. To avoid overwriting and instead
throw an error if the blob exists, please pass in an accessConditions
parameter in the options object.
所以你用 Azure Storage SDK for Node 覆盖现有的 blob 文件是正确的。
编辑:
您似乎遇到了上传问题。我建议您尝试使用 createWriteStreamToBlockBlob 而不是 createBlockBlobFromStream
将 blob 上传到 Azure 存储。
以下示例通过使用 connect-busboy 中间件工作。创建 /public 文件夹。
使用文件夹结构:
\index.js
\public\index.html
INDEX.JS
var express = require('express')
var app = express()
var busboy = require('connect-busboy')
var azure = require('azure-storage')
var accountName = "<acountName>"
var accountKey = "<accountKey>"
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);
req.busboy.on('file', function(fieldname, file, filename) {
var blobSvc = azure.createBlobService(accountName, accountKey)
file.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', filename, function(error) {
if (!error) {
res.send(200, 'upload succeeded')
} else {
res.send(500, JSON.stringify(error))
}
}))
})
})
app.listen(process.env.PORT || 3000, function() {
console.log('Example app listening on port 3000!')
})
INDEX.HTML
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
新问题
When I overwrite a blob and then update the browser is still caching the main image and not the new one. I have read that there is a cache-control property but I can not implement it. I need to clean the blob cache that has just been uploaded
老问题
我正在尝试使用 connect-busboy 中间件和以下方法覆盖现有的 blob,但文件没有被覆盖,我不明白为什么。
createBlockBlobFromStream(container, blob, (Stream), streamLength,
options, callback) → {SpeedSummary}Uploads a block blob from a stream. If the blob already exists on the service, it will be overwritten.
app.post('/upload', function(req, res, params) {
var name;
req.busboy.on('field', function (fieldname, val) {
name = val+'.jpg';
});
req.busboy.on('file', function (fieldname, file, filename, encoding, mimetype) {
file.on('data', function (data) {
console.log(name);
console.log(data);
var bufferStream = new stream.PassThrough();
bufferStream.end(data);
var blobSvc = azure.createBlobService(accountName, accountKey);
blobSvc.createBlockBlobFromStream('images', name, bufferStream, data.length, function (error, result, response){
if (!error) {
res.send(200,'upload succeeded')
} else {
res.send(500,JSON.stringify(error))
}
})
});
});
});
每 Azure Storage SDK for Node API Reference,
createBlockBlobFromStream(container, blob, (Stream), streamLength, options, callback) → {SpeedSummary}
Uploads a block blob from a stream. If the blob already exists on the service, it will be overwritten. To avoid overwriting and instead throw an error if the blob exists, please pass in an accessConditions parameter in the options object.
所以你用 Azure Storage SDK for Node 覆盖现有的 blob 文件是正确的。
编辑:
您似乎遇到了上传问题。我建议您尝试使用 createWriteStreamToBlockBlob 而不是 createBlockBlobFromStream
将 blob 上传到 Azure 存储。
以下示例通过使用 connect-busboy 中间件工作。创建 /public 文件夹。
使用文件夹结构:
\index.js
\public\index.html
INDEX.JS
var express = require('express')
var app = express()
var busboy = require('connect-busboy')
var azure = require('azure-storage')
var accountName = "<acountName>"
var accountKey = "<accountKey>"
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);
req.busboy.on('file', function(fieldname, file, filename) {
var blobSvc = azure.createBlobService(accountName, accountKey)
file.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer', filename, function(error) {
if (!error) {
res.send(200, 'upload succeeded')
} else {
res.send(500, JSON.stringify(error))
}
}))
})
})
app.listen(process.env.PORT || 3000, function() {
console.log('Example app listening on port 3000!')
})
INDEX.HTML
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>