Home > database >  How to get data from json file stored in Azure blob storage in react
How to get data from json file stored in Azure blob storage in react

Time:04-08

I'm new to react and azure i want to store a json file on azure blob storage and get the data of that json file into react js

I don't know where to start can someone help me please

CodePudding user response:

To store Json file in Azure blob storage, please try the following:

  • Create a container using below cmdlet
azcopy make 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>'
  • To Upload a file, make use of below cmdlet
azcopy copy '<local-file-path>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>/<blob-name>'

You can also upload a file by using a wildcard symbol (*) anywhere in the file path or file name as C:\my*\*.txt.

  • To Upload a specific files, make use of below cmdlet
azcopy copy '<local-directory-path>' 'https://<storage-account-name>.<blob or dfs>.core.windows.net/<container-name>' --include-path <semicolon-separated-file-list>

For more in detail, please refer below links:

Upload files to Azure Blob storage by using AzCopy v10 | Microsoft Docs. node.js - Store json object to Azure blob storage - Stack Overflow.

To Get data of Json file into React js, please try the following:

  • Enable CORS for your Resource through Azure portal.
  • Try accessing the blob by using below sample snippet:
export function getJsonData<T = any>(url: string): Promise<T> {
return fetch(url, {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
}
})
.then(response => {
return response.json();
})
.catch(error => {
return Promise.reject(error);
});}

For more in detail, please refer below link:

reactjs - Get json file data which stored in Azure blob storage in React - Stack Overflow.

  • Related