Я пытаюсь загрузить файлы из хранилища BLOB-объектов Azure через restful API.
У меня есть следующий фрагмент, который возвращает URL-адрес, аналогичный тому, который вы можете автоматически сгенерировать через их портал.< /p>
async fetchBlobUrl (containerName: string, blobId: string): Promise {
// Step 1: Prepare the canonical URL path for the blob
const urlPath = `/${containerName}/${blobId}`
// Step 2: Set SAS token parameters
const expiryDate = new Date(new Date().valueOf() + 3600 * 1000) // Expiry is 1 hour from now
const expiry = expiryDate.toISOString().slice(0, 19) + 'Z' // Format: 2025-01-16T14:33:00Z
const startDate = new Date() // Start time is now
const startTime = startDate.toISOString().slice(0, 19) + 'Z' // Format: 2025-01-16T13:33:00Z
const permissions = 'r' // Read permission
const sasVersion = '2022-11-02' // SAS API version
const protocol = 'https' // Protocol should be https
const resourceType = 'b' // 'b' for blob
// Step 3: Construct the canonical string to sign (fixing the structure)
const stringToSign = [
permissions, // permissions
startTime, // start time
expiry, // expiry
`/blob/${this.accountName}/${containerName}/${blobId}`, // the blob's URL path
'', // identifier (optional)
'', // IP (optional)
protocol, // protocol (https)
sasVersion, // SAS version
resourceType, // resource type ('b' for blob)
].join('\n')
// Step 4: Create a signature using your account key
const hash = crypto
.createHmac('sha256', Buffer.from(this.accountKey, 'base64'))
.update(stringToSign, 'utf8')
.digest('base64')
// Step 5: Generate the SAS token by appending the signature
const sasToken = `sp=${permissions}&st=${startTime}&se=${expiry}&spr=${protocol}&sv=${sasVersion}&sr=${resourceType}&sig=${encodeURIComponent(hash)}`
// Step 6: Construct the final blob URL
return Promise.resolve(`https://${this.accountName}.blob.core.windows.net${urlPath}?${sasToken}`)
}
Но каждый раз, когда я тестирую, я получаю ошибку:
Signature did not match. String to sign used was etc etc etc
Подробнее здесь: https://stackoverflow.com/questions/793 ... ob-storage
Пытаетесь скачать файл из хранилища BLOB-объектов Azure? ⇐ Javascript
Форум по Javascript
-
Anonymous
1737038755
Anonymous
Я пытаюсь загрузить файлы из хранилища BLOB-объектов Azure через restful API.
У меня есть следующий фрагмент, который возвращает URL-адрес, аналогичный тому, который вы можете автоматически сгенерировать через их портал.< /p>
async fetchBlobUrl (containerName: string, blobId: string): Promise {
// Step 1: Prepare the canonical URL path for the blob
const urlPath = `/${containerName}/${blobId}`
// Step 2: Set SAS token parameters
const expiryDate = new Date(new Date().valueOf() + 3600 * 1000) // Expiry is 1 hour from now
const expiry = expiryDate.toISOString().slice(0, 19) + 'Z' // Format: 2025-01-16T14:33:00Z
const startDate = new Date() // Start time is now
const startTime = startDate.toISOString().slice(0, 19) + 'Z' // Format: 2025-01-16T13:33:00Z
const permissions = 'r' // Read permission
const sasVersion = '2022-11-02' // SAS API version
const protocol = 'https' // Protocol should be https
const resourceType = 'b' // 'b' for blob
// Step 3: Construct the canonical string to sign (fixing the structure)
const stringToSign = [
permissions, // permissions
startTime, // start time
expiry, // expiry
`/blob/${this.accountName}/${containerName}/${blobId}`, // the blob's URL path
'', // identifier (optional)
'', // IP (optional)
protocol, // protocol (https)
sasVersion, // SAS version
resourceType, // resource type ('b' for blob)
].join('\n')
// Step 4: Create a signature using your account key
const hash = crypto
.createHmac('sha256', Buffer.from(this.accountKey, 'base64'))
.update(stringToSign, 'utf8')
.digest('base64')
// Step 5: Generate the SAS token by appending the signature
const sasToken = `sp=${permissions}&st=${startTime}&se=${expiry}&spr=${protocol}&sv=${sasVersion}&sr=${resourceType}&sig=${encodeURIComponent(hash)}`
// Step 6: Construct the final blob URL
return Promise.resolve(`https://${this.accountName}.blob.core.windows.net${urlPath}?${sasToken}`)
}
Но каждый раз, когда я тестирую, я получаю ошибку:
Signature did not match. String to sign used was etc etc etc
Подробнее здесь: [url]https://stackoverflow.com/questions/79362020/trying-to-download-file-from-azure-blob-storage[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия