wtk*_*219 3 azure-storage-blobs
我正在尝试使用Azure Blob存储来存储Blob,但是大部分时间我都会从Blob存储中获得“请求中止”响应。我在Express API中使用Node.js v10 SDK,并且感觉到它与我配置服务的方式有关。
我正在使用Azurite模仿Azure存储服务。
在我的app.js中,我configureBlobStore()在启动时运行函数:
export const configureBlobStore = async containerName => {
const sharedKeyCredential = new SharedKeyCredential(
process.env.AZURE_STORAGE_ACCOUNT_NAME,
process.env.AZURE_STORAGE_ACCOUNT_ACCESS_KEY,
);
const pipeline = StorageURL.newPipeline(sharedKeyCredential);
serviceUrl = new ServiceURL('http://blob:10000/devstoreaccount1', pipeline);
if (!containerUrl) {
containerUrl = ContainerURL.fromServiceURL(serviceUrl, containerName);
try {
await containerUrl.create(aborter);
} catch (err) {
console.log(err);
console.log('Container already existed, skipping creation');
}
}
return containerUrl;
};
Run Code Online (Sandbox Code Playgroud)
然后保存斑点,我运行我的函数 saveToBlobStore()
let { originalname: blobName } = file;
const blockBlobUrl = BlockBlobURL.fromContainerURL(containerUrl, blobName);
const uploadOptions = { bufferSize: 4 * 1024 * 1024, maxBuffers: 20 };
const stream = intoStream(file.buffer);
try {
await uploadStreamToBlockBlob(
aborter,
stream,
blockBlobUrl,
uploadOptions.bufferSize,
uploadOptions.maxBuffers,
);
return blockBlobUrl.url;
} catch (err) {
console.error('Error saving blob', err);
return err;
}
};
Run Code Online (Sandbox Code Playgroud)
有时它可以工作,通常是当我拿下容器并进行批量修剪时,但通常它只对上传的第一个文件有效,而对其他文件不起作用。有谁知道为什么会这样?
| 归档时间: |
|
| 查看次数: |
196 次 |
| 最近记录: |