以下是帖子请求JSON
:
{
"name":"images.jpg",
"file":"data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQTEhIUEhIUFBUV…K9rk8hCAEkjFMUYiEAI+nHIpsQh0AkisDYRTOiCAbWVtgCtI6IlkHh7LDTQXLH0EIQBj//2Q=="
}
此处是请求/upload
路由下的节点控制器,我正在使用azure-storage中的createBlockBlobFromText()
。
var azure = require('azure-storage');
var blobSvc = azure.createBlobService('myblob.blob.core.windows.net/mycontainer', THE_KEY);
controllers.upload = function (req, res, next){
var startDate = new Date();
var expiryDate = new Date(startDate);
var sharedAccessPolicy = {
AccessPolicy: {
Permissions: azure.BlobUtilities.SharedAccessPermissions.WRITE,
Start: startDate,
Expiry: expiryDate
}
};
var sharedAccessSignatureToken = blobSvc.generateSharedAccessSignature('resources', req.body.file, sharedAccessPolicy);
var sharedBlobService = azure.createBlobServiceWithSas(blobSvc.host.primaryHost + '/' + 'mycontainer' + '?' + sharedAccessSignatureToken);
sharedBlobService.createBlockBlobFromText('mycontainer', req.body.name, req.body.file, function(error, result, response) {
if (error) {
res.send(error);
return;
}
res.send(result);
});
}
但是我收到了这个错误。
{
"code": "ResourceNotFound",
"statusCode": 404,
"requestId": "bffa6099-0001-000b-53f9-80d18a000000"
}
答案 0 :(得分:3)
需要做出一些改变:
完成这些更改后,代码将与此类似:
var sharedAccessSignatureToken = blobSvc.generateSharedAccessSignature('mycontainer', req.body.name, sharedAccessPolicy);
var sharedBlobService = azure.createBlobServiceWithSas(blobSvc.host, sharedAccessSignatureToken);
sharedBlobService.createBlockBlobFromText('mycontainer', req.body.name, req.body.file, function(error, result, response) {
if (error) {
res.send(error);
return;
}
res.send(result);
});