This is a brief example of how to upload files to Azure Storage using X++ code
Please note that you will need the URL to connect to the container, as well as the access key.
Points to keep in mind:
- Use access keys to authenticate your applications and make requests to your Azure storage account (Manage account access keys – Azure Storage | Microsoft Docs).
- Store your access keys securely, for example with Azure Key Vault, and do not share them.
- We recommend regenerating your access keys regularly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | using BlobStorage = Microsoft.WindowsAzure.Storage; using Microsoft.Dynamics.AX.Framework.FileManagement; using System.IO; class SavFileAzureBlobStorageJob { public static void main(Args _args) { CommaStreamIo io = CommaStreamIo::constructForWrite(); CustTable custTable; const str connectionString = "YOUR_CONNECTION_STRING" ; const str containerName = "YOUR_CONTAINER_NAME" ; const str fileName = "customers.csv" ; BlobStorage.CloudStorageAccount storageAccount = BlobStorage.CloudStorageAccount::Parse(connectionString); BlobStorage.Blob.CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); BlobStorage.Blob.CloudBlobContainer blobContainer = blobClient.GetContainerReference(containerName); blobContainer.CreateIfNotExistsAsync(); io.writeExp([ 'Account Number' , 'Customer' , 'Currency' , 'Data Area' ]); while select custTable where custTable.DataAreaId == 'USMF' { io.writeExp([custTable.AccountNum, custTable.name(), custTable.Currency, custTable.DataAreaId]); } BlobStorage.Blob.CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(fileName); if (blockBlob && !blockBlob.Exists( null , null )) { System.IO.Stream stream = iO.getStream(); stream.Position = 0; System.IO.StreamReader reader = new System.IO.StreamReader(stream); str csvFileContent = reader.ReadToEnd(); if (csvFileContent) { blockBlob.UploadText(csvFileContent, null , null , null , null ); blockBlob.FetchAttributes( null , null , null ); BlobStorage.Blob.BlobProperties blobProperties = blockBlob.Properties; if (blobProperties.Length != 0) { info( 'File upload successful' ); } } } else { info( 'File already exits' ); } } } |
En el siguiente enlace, el cliente puede encontrar la documentación de cómo crear una cuenta de almacenamiento de Azure en su única cuenta de Azure (suscripción Pay as You Go) o AIS