I'm trying to upload a CSV file to an Azure container using Axios in a backend NodeJS application. This is my code:
const BlobUriWithSASToken = 'https://myContainerName.blob.core.windows.net/folder1/folder2/folder3/folder4/mytestfile.csv?sv=<SAS Token>';
const form = new FormData();
form.append(
'file',
fs.createReadStream(path.join(__dirname + '/mytestfile.csv')),
);
const request_config = {
headers: {
'Content-Length': 52,
'x-ms-blob-type': 'BlockBlob',
...form.getHeaders(),
},
};
try {
const response = await axios.put(
BlobUriWithSASToken,
form,
request_config,
);
expect(response.status).toEqual(201);
} catch (err) {
console.log(err);
}
However, running this test returns a 403 - Forbidden. These are the error details:
status: 403,
statusText: 'This request is not authorized to perform this operation.',
My CSV is a small 52 bytes file.
Initially, I got the same error when I run the same code in my environment.
The 403 error indicates that the request was not authorized to perform the operation. There could be some possible reasons.
?there if it is there remove and paste it because you have already mentioned it in the URL.I tried with the below code to upload CSV files using Axios in a backend NodeJS application.
Code:
Output:
The above code is executed and uploaded CSV file successfully.
Portal: