gpt4 book ai didi

angular - 无法使用 Angular-azure-blob-service 生成 'sas' token

转载 作者:行者123 更新时间:2023-12-03 04:18:14 28 4
gpt4 key购买 nike

 if (fileUpload !== null) {
const baseUrl = this.blob.generateBlobUrl(Config,'testBlobUpload');
this.config = {
baseUrl: baseUrl,
sasToken: Config.sas,
blockSize: 1024 * 64, // OPTIONAL, default value is 1024 * 32
file: fileUpload.nativeFile,
complete: () => {
console.log('Transfer completed !');
},
error: () => {
console.log('Error !');
},
progress: (percent) => {
//this.percent = percent;
}
};
this.blob.upload(this.config);
}


export const Config: UploadParams = {
sas:'?sv=2017-07-29&sr=b&sig=q80fVo0wp8SVmTcgae%2BjceUPfKjE3Eb2MYbkClm8EqQ%3D&st=2018-03-06T13%3A49%3A33Z&se=2018-11-01T13%3A49%3A33Z&sp=racw',
storageAccount: 'vldevstoragefuncapp.blob.core.windows.net/vl2songs',
containerName: 'vl2songs'
//?sv=2017-07-29&sr=b&sig=QXVl6BcV47WiOPbM8CeNhmGpC%2FNslyN7qnI%2BopLuXyg%3D&st=2018-03-06T11%3A46%3A49Z&se=2018-11-01T11%3A46%3A50Z&sp=rw
}

使用 Angular5 使用 angular-azure-blob-service 在 Azure blob 上上传媒体文件,我在生成“sas” token 时遇到问题,如果有人使用帮助我,谢谢

enter image description here

enter image description here

最佳答案

要在 Angular 2+ 中生成 SAS token ,您需要安装 - create-hmac

npm i create-hmac

需要插入到index.html

<head>
...

<script>
var global = global || window;
var Buffer = Buffer || [];
var process = process || {
env: { DEBUG: undefined },
version: []
};
</script>
</head>

生成 token -

public generateSasToken(resourceUri: string, signingKey: string, policyName: string, expiresInMins: number) {
resourceUri = encodeURIComponent(resourceUri);
let expires = (Date.now() / 1000) + expiresInMins * 60;
expires = Math.ceil(expires);
const toSign = resourceUri + '\n' + expires;

// Use crypto
const createHmac = require('create-hmac');
const Buffer = require('buffer').Buffer;
const hmac = createHmac('sha256', Buffer.from(signingKey, 'base64'));
hmac.update(toSign);
const base64UriEncoded = encodeURIComponent(hmac.digest('base64'));

// Construct authorization string
let token = 'SharedAccessSignature sr=' + resourceUri + '&sig='
+ base64UriEncoded + '&se=' + expires;
if (policyName) {
token += '&skn=' + policyName;
}
return token;
}

关于angular - 无法使用 Angular-azure-blob-service 生成 'sas' token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51168830/

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