I came across some weird behavior. I have to upload file to azure storage and I am using package to upload.
OnProgress
callback is getting completed means my file is uploaded successfully.
But as soon as I call, azure api to fetch files again it's not returning that latest uploaded file.
If I am calling fetch api in setInterval
then in some of the call I am getting this file.
So is it related to concurrency at azure or I am doing something wrong here?
const sassUrl = generateSasUrl() // to generate sasUrl
const azureClient = new ContainerClient(sassUrl).getBlobClient(fileName)
azureClient.uploadData(file , {
onProgress: ({loadedBytes}) => {
const isUploaded = loadedBytes === fileSize;
if(isUploaded){
fetchAzureFiles()
}
}
})
async function fetchAzureFiles(){
const url = `https://${accoutnName}/blob.core.windows.net/${containerName}`;
const containerClient = new ContainerClient(containerUrl, new ManagedIdentityCredential(clientId, UAMI_CLient_id));
const files = await containerClient.listAdlsFiles();
return files
}
Here is the way i'm able to call, azure api to fetch files again, below code will call the Azure API to fetch files again after uploading a file to the container. This is because the
fetchAzureFiles
function is called within theuploadFileToAzureStorage
function after the file has been uploaded. ThefetchAzureFiles
function retrieves the list of files in the container, which includes the newly uploaded file.Result