how to fix CORS permissions when uploading file to Azure Data Lake using blockBlobClient.upload?

javier cohenar 196 Reputation points
2023-11-07T20:31:31.5666667+00:00

Following the docs I have the following code for uploading a file from String that leads to a CORS error

export async function uploadBlobFromString(containerName, path, fileContentsAsString){
  try{
    // Create blob client from container client
    debugger
    let blobName = 'https://' + `${account}` + '.blob.core.windows.net/' + `${path}` + `${accountKey}`
    console.log(blobName)
    const blobServiceClient = new BlobServiceClient(blobName);
    const containerClient = blobServiceClient.getContainerClient(containerName);
    const blockBlobClient = containerClient.getBlockBlobClient(blobName);

    await blockBlobClient.upload(fileContentsAsString, fileContentsAsString.length);
    return true
  }catch(e){
    console.log(e)
    throw (e)
  }
  
}

However CORS configuration at the storage level seems ok to me:

cors

Would much appreciate your help

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,843 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anand Prakash Yadav 7,785 Reputation points Microsoft Vendor
    2023-11-09T12:36:19.3266667+00:00

    Hi javier cohenar,

    Thank you for posting your query here!

    If you are trying to upload file into Azure Data Lake store, you can use @azure/storage-file-datalake package to interact with Azure Data Lake Storage.

    You can find some samples for interacting with it here: https://learn.microsoft.com/en-us/azure/storage/blobs/data-lake-storage-directory-file-acl-javascript

    Code sample for uploading a file from the same link.

    Please let us know if you have any further queries. I’m happy to assist you further.
    If you are still experiencing issues, it may be helpful to provide specific error messages.


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.