I am trying to upgrade my code from v10 to v12 but have no idea on how to go forward. Can someone help me out with it please?
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);
}
This is what I have done.
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);
}
Where does blockBlobURL value gets passed into as opposed to the old code? Thanks.
Please advice.
In v12 of the @azure/storage-blob SDK you can directly instantiate the BlockBlobClient
with your URL that contains a SAS token.
import { BlockBlobClient } from "@azure/storage-blob";
export function uploadToAzure(blobUrl: string , blob: Blob) {
const client = new BlockBlobClient(blobUrl);
return client.uploadBrowserData(blob);
}
The blob url with SAS token is provided as the first parameter when instantiating the BlockBlobClient
. It is no longer required to pass in the AnonymousCredential
since this will be used by default if no credential object is provided.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.