Reference1: https://learn.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url
Reference2: Authorization of Azure Storage service REST API
I implemented listing of containers according to the above reference2 as a backend server in Next.js (/pages/api/). I got the implementation in Reference2 to work with response status===OK. My goal is to copy a blob with tier===cool and paste it into a different container with tier===archive so I don't have to change the archived blob's access tier when downloading it.
I follow exactly reference2 with the following changes:
- set strToSign to (least sure about this part):
const strToSign= PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:${strTime}\nx-ms-version:2020-10-02\n/${account}/\n${containerName}/${blobName}
set header (following reference1) to:
const putConfig = { method: 'PUT', headers: { 'Authorization': auth, 'x-ms-date': strTime, 'x-ms-version': "2020-10-02", 'x-ms-copy-source': blobUrl, 'x-ms-requires-sync':'true' }
}
where (as in reference1),
const blobUrl = `https://${account}.blob.core.windows.net/${containerName}/${blobName}`
The fetch is set up like this:
fetch(
https://${account}.blob.core.windows.net/${containerName}/${blobName}
, putConfig) .then( results => console.log(results), res.end())This is the console.log(results) output I get:
Response { size: 0, timeout: 0, [Symbol(Body internals)]: { body: PassThrough { _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 2, _maxListeners: undefined, _writableState: [WritableState], allowHalfOpen: true, [Symbol(kCapture)]: false, [Symbol(kCallback)]: null }, disturbed: false, error: null }, [Symbol(Response internals)]: { url: 'https://.blob.core.windows.net//', status: 403, statusText: 'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.', headers: Headers { [Symbol(map)]: [Object: null prototype] }, counter: 0 } }
Not sure what the error is - can it be related to setting access on the specific blob (resource) on azure portal? How do you fix this issue?
P.S.
Reference3: Authentication Failed in REST api call to PUT Blob in Azure Storage [REST][Azure Blob]
I also tried to use the following:
const strToSign = `PUT\n\n\n\n\n\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-date:${strTime}\nx-ms-version:2020-10-02\n/${account}/\n${containerName}/\n${blobName}`;
The error remains the same.