【发布时间】:2021-06-09 10:08:21
【问题描述】:
**我正在创建一个将生成 sasurl 的类,我需要将文件上传到前端。我将在其他模块中使用 BlobStorageApi 类来创建 API。但是当我运行这段代码时,我得到了 SyntaxError: Unexpected identifier。这段代码之前不在课堂上并且正在工作,但是在我把它放在课堂上之后它给了我一个错误。
const storage = require("@azure/storage-blob");
class BlobStorageAPI {
blobServiceClient: any;
containerName: string;
client: any;
blobName: string;
blobClient: any;
creds: any;
constructor(account, accountKey, accountName) {
const creds = new storage.StorageSharedKeyCredential(account, accountKey);
this.blobServiceClient = new storage.BlobServiceClient(
`https://${accountName}.blob.core.windows.net`,
creds
);
this.containerName = 'text'
this.client = this.blobServiceClient.getContainerClient(this.containerName)
this.blobName = 'help.txt'
this.blobClient = this.client.getBlobClient(this.blobName)
}
get blobSAS() {
return storage
.generateBlobSASQueryParameters({
containerName:this.containerName,
blobName: this.blobName,
permissions: storage.BlobSASPermissions.parse("racwd"),
startsOn: new Date(),
expiresOn: new Date(new Date().valueOf() + 86400),
},
this.creds
).toString();
}
get sasUrl() {
return this.blobClient.url + "?" + this.blobSAS;
}
}
const api = new BlobStorageAPI('joey','/Zs0kjnFoKtKqDPdiAV/61+pTdRhr5H5Wd5vQheXoEtuTOjtWLp6w==', "blobstorage0420");
console.log(api.blobSAS);
console.log();
console.log(api.sasUrl);
【问题讨论】:
标签: javascript typescript class constructor azure-blob-storage