Noticed while trying to use this new library that uploading files that contains spaces result in authentication error.
// @ts-check
const { StorageURL, ServiceURL, SharedKeyCredential, uploadFileToBlockBlob, Aborter, ContainerURL, BlobURL, BlockBlobURL } = require("@azure/storage-blob");
const pipeline = StorageURL.newPipeline(
new SharedKeyCredential("[account]", ""),
);
// List containers
const serviceURL = new ServiceURL(
"https://[account].blob.core.windows.net",
pipeline,
);
const containerURL = ContainerURL.fromServiceURL(serviceURL, "test");
const blobURL = BlobURL.fromContainerURL(containerURL, "blob with spaces.txt");
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
uploadFileToBlockBlob(Aborter.None, "./file with spaces.txt", blockBlobURL).then(() => {
console.log("Success")
}).catch((e) => {
console.log("Error", e);
})
Error { Error: <?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:4f27d66f-501e-0017-53a0-4e8893000000
Time:2018-09-17T16:07:02.7426199Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'd65Ec7bxhPHYaFNLPd5jIsUSAonRmxOgbSf/7owR25U=' is not the same as any computed signature. Server used following string to sign: 'PUT
12
application/octet-stream
x-ms-blob-type:BlockBlob
x-ms-client-request-id:4c723297-519f-4655-a05c-853e83d2f841
x-ms-date:Mon, 17 Sep 2018 16:07:01 GMT
x-ms-version:2018-03-28
/testtim1/test/blob%20with%20spaces.txt
timeout:60000'.</AuthenticationErrorDetail></Error>
at new RestError (D:\dev\test\node_modules\ms-rest-js\dist\lib\restError.js:9:28)
at D:\dev\test\node_modules\ms-rest-js\dist\lib\policies\deserializationPolicy.js:89:37
at process._tickCallback (internal/process/next_tick.js:68:7)
code: undefined,
statusCode: 403,
request:
WebResource {
streamResponseBody: false,
url:
'https://testtim1.blob.core.windows.net/test/blob with spaces.txt?timeout=60000',
method: 'PUT',
headers: HttpHeaders { _headersMap: [Object] },
body: [Function],
query: undefined,
formData: undefined,
withCredentials: false,
abortSignal:
Aborter {
_aborted: false,
children: [],
abortEventListeners: [],
parent: undefined,
key: undefined,
value: undefined },
timeout: 0,
onUploadProgress: undefined,
onDownloadProgress: undefined,
operationSpec:
{ httpMethod: 'PUT',
path: '{containerName}/{blob}',
urlParameters: [Array],
queryParameters: [Array],
headerParameters: [Array],
requestBody: [Object],
contentType: 'application/octet-stream',
responses: [Object],
isXML: true,
serializer: [Serializer] },
shouldDeserialize: undefined,
operationResponseGetter: undefined },
response:
{ body:
'<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:4f27d66f-501e-0017-53a0-4e8893000000\nTime:2018-09-17T16:07:02.7426199Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request \'d65Ec7bxhPHYaFNLPd5jIsUSAonRmxOgbSf/7owR25U=\' is not the same as any computed signature. Server used following string to sign: \'PUT\n\n\n12\n\napplication/octet-stream\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-client-request-id:4c723297-519f-4655-a05c-853e83d2f841\nx-ms-date:Mon, 17 Sep 2018 16:07:01 GMT\nx-ms-version:2018-03-28\n/testtim1/test/blob%20with%20spaces.txt\ntimeout:60000\'.</AuthenticationErrorDetail></Error>',
headers: HttpHeaders { _headersMap: [Object] },
status: 403 },
body:
{ message:
'Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.\nRequestId:4f27d66f-501e-0017-53a0-4e8893000000\nTime:2018-09-17T16:07:02.7426199Z' } }
As soon as I remove the spaces from the blob name it uploads just fine.