Node.js 覆盖Azure存储中的现有blob不适用于节点 新问题
当我覆盖一个blob然后更新时,浏览器仍在缓存 主图像,而不是新图像。我读到有一篇文章 缓存控件属性,但我无法实现它。我需要打扫房间 刚刚上载的blob缓存 老问题 我正在尝试使用connect busboy中间件和以下方法覆盖现有blob,但该文件没有被覆盖,我不明白为什么 createBlockBlobFromStream(容器、blob、(流)、streamLength,Node.js 覆盖Azure存储中的现有blob不适用于节点 新问题,node.js,azure,file-upload,stream,busboy,Node.js,Azure,File Upload,Stream,Busboy,当我覆盖一个blob然后更新时,浏览器仍在缓存 主图像,而不是新图像。我读到有一篇文章 缓存控件属性,但我无法实现它。我需要打扫房间 刚刚上载的blob缓存 老问题 我正在尝试使用connect busboy中间件和以下方法覆盖现有blob,但该文件没有被覆盖,我不明白为什么 createBlockBlobFromStream(容器、blob、(流)、streamLength, 选项,回调)→ {SpeedSummary} 从流上载块blob。如果该blob已存在于 服务,它将被覆盖 每 cre
选项,回调)→ {SpeedSummary} 从流上载块blob。如果该blob已存在于 服务,它将被覆盖 每
createBlockBlobFromStream(容器、blob、(流)、streamLength、,
选项,回调)→ {SpeedSummary}
从流上载块blob如果blob已存在于
服务,它将被覆盖。以避免覆盖,而不是
抛出错误如果blob存在,请传入accessConditions
选项对象中的参数
因此,使用Azure Storage SDK for Node覆盖现有blob文件是正确的
编辑:
似乎您遇到了上载问题。我建议您尝试使用而不是createBlockBlobFromStream
将blob上载到Azure存储。
下面的示例使用connect busboy中间件工作。创建/公开文件夹。
使用文件夹结构:
\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=“”
var accountKey=“”
app.use(busboy())
应用程序使用(express.static('public'))
app.get('/',函数(req,res){
res.sendFile('index.html')
})
app.post('/upload',函数(req、res、params){
所需管道(所需汇流排);
请求busboy.on('file',函数(字段名、文件名、文件名){
var blobSvc=azure.createBlobsService(accountName,accountKey)
file.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer',文件名,函数)(错误){
如果(!错误){
res.send(200,‘上传成功’)
}否则{
res.send(500,JSON.stringify(错误))
}
}))
})
})
app.listen(process.env.PORT | | 3000,函数(){
log('端口3000上侦听的示例应用程序!')
})
INDEX.HTML
样品
选择要上载的图像:
根据
createBlockBlobFromStream(容器、blob、(流)、streamLength、,
选项,回调)→ {SpeedSummary}
从流上载块blob如果blob已存在于
服务,它将被覆盖。以避免覆盖,而不是
抛出错误如果blob存在,请传入accessConditions
选项对象中的参数
因此,使用Azure Storage SDK for Node覆盖现有blob文件是正确的
编辑:
似乎您遇到了上载问题。我建议您尝试使用而不是createBlockBlobFromStream
将blob上载到Azure存储。
下面的示例使用connect busboy中间件工作。创建/公开文件夹。
使用文件夹结构:
\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=“”
var accountKey=“”
app.use(busboy())
应用程序使用(express.static('public'))
app.get('/',函数(req,res){
res.sendFile('index.html')
})
app.post('/upload',函数(req、res、params){
所需管道(所需汇流排);
请求busboy.on('file',函数(字段名、文件名、文件名){
var blobSvc=azure.createBlobsService(accountName,accountKey)
file.pipe(blobSvc.createWriteStreamToBlockBlob('mycontainer',文件名,函数)(错误){
如果(!错误){
res.send(200,‘上传成功’)
}否则{
res.send(500,JSON.stringify(错误))
}
}))
})
})
app.listen(process.env.PORT | | 3000,函数(){
log('端口3000上侦听的示例应用程序!')
})
INDEX.HTML
样品
选择要上载的图像:
您在上述代码中看到的行为是什么?你犯了什么错误?请编辑您的问题以使其更清楚。您在上面的代码中看到了什么行为?你犯了什么错误?请编辑您的问题以使其更清晰。非常感谢您的回答。我用了很多。我使用你的代码,它的工作原理和我的一样。我怀疑门户azure管理员将通过门户上的某些选项阻止覆盖权限。他几周后来。无论如何,您的代码用于验证并确认问题是另一个问题。非常感谢你!或者可能是前端缓存问题,我使用Angular2非常感谢您的回答。我用了很多。我使用你的代码,它的工作原理和我的一样。我怀疑门户azure管理员将通过门户上的某些选项阻止覆盖权限。他几周后来。无论如何,您的代码用于验证并确认问题是另一个问题。非常感谢你!或者可能是前端缓存问题,我使用angular2
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))
}
})
});
});
});
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!')
})
<!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>