gpt4 book ai didi

javascript - 从 v10 升级到 v12 - AzureSDK JS

转载 作者:行者123 更新时间:2023-12-02 21:29:17 27 4
gpt4 key购买 nike

我正在尝试将代码从 v10 升级到 v12,但不知道如何继续。有人可以帮我吗?

import {
Aborter,
AnonymousCredential,
BlobUploadCommonResponse,
BlockBlobURL,
StorageURL,
uploadBrowserDataToBlockBlob
} from '@azure/storage-blob';

import { Upload } from '../types/models';

const CREDENTIALS = new AnonymousCredential();
const PIPELINE = StorageURL.newPipeline(CREDENTIALS);

export function uploadToAzure(upload: Upload, blob: Blob, options: {} = {}): Promise<BlobUploadCommonResponse> {
const blockBlobURL = new BlockBlobURL(upload.BlobURL, PIPELINE);

return uploadBrowserDataToBlockBlob(Aborter.none, blob, blockBlobURL, options);
}

这就是我所做的。

import {
Aborter,
AnonymousCredential,
BlobUploadCommonResponse,
BlobServiceClient
uploadBrowserData,
newPipeline
} from '@azure/storage-blob';

import { Upload } from '../types/models';

const CREDENTIALS = new AnonymousCredential();
const PIPELINE = newPipeline(CREDENTIALS);

export function uploadToAzure(upload: Upload, blob: Blob, options: {} = {}): Promise<BlobUploadCommonResponse> {
const blockBlobURL = new BlobServiceClient(upload.BlobURL, PIPELINE);

return uploadBrowserData(blob, options);
}

与旧代码相比,blockBlobURL 值传递到哪里?谢谢。

请指教。

最佳答案

在 @azure/storage-blob SDK v12 中,您可以使用包含 SAS token 的 URL 直接实例化 BlockBlobClient

import { BlockBlobClient } from "@azure/storage-blob";

export function uploadToAzure(blobUrl: string , blob: Blob) {
const client = new BlockBlobClient(blobUrl);
return client.uploadBrowserData(blob);
}

实例化 BlockBlobClient 时,带有 SAS token 的 Blob URL 作为第一个参数提供。不再需要传入 AnonymousCredential,因为如果未提供凭据对象,则默认使用此值。

文档: https://learn.microsoft.com/en-us/javascript/api/@azure/storage-blob/blockblobclient?view=azure-node-latest#blockblobclient-string--storagesharedkeycredential---anonymouscredential---tokencredential--storagepipelineoptions-

关于javascript - 从 v10 升级到 v12 - AzureSDK JS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60661540/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com