web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / File upload to Azure b...
Finance forum

File upload to Azure blob storage

(0) ShareShare
ReportReport
Posted on by

Hello! I am trying to upload local file to Azure blob storage via X++ code. I am receiving following error for UploadFromFile and UploadFromFileAsync methods among many others I tried. Please see the error message along with code snippet below.

screen1.jpg

Method 'UploadFromFile(System.Object)' is not found on type 'Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob'.


using Microsoft.Azure; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Blob; using Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer; using Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob; using Microsoft.WindowsAzure.Storage.File; Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials = new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials(accountName, accountKey); Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true); var blobcli = storageAccount.CreateCloudBlobClient(); Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer cont = blobcli.GetContainerReference("from-d365"); CloudBlockBlob cloudBlockBlob = cont.GetBlockBlobReference(fileName); cloudBlockBlob.UploadFromFile(targetFile);


I have the same question (0)
  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    Hi Janis Plavins,

    Try to pass FileMode  as second parameter (i.e. FileMode.Open). I know that example says that you can use only one parameter but it obviously does not work :)

  • Verified answer
    Ivan Valdes Profile Picture
    100 on at

    Hi Janis,

    I think the problem is that you are using uploadFromFile with only one parameter and it needs more parameters.

    I see the next parameters in my visual studio (2 mandatory parameters):

    5050.Capture.PNG

    If you read the MSFT doc, your code is right, but it could be a different version.

    https://docs.microsoft.com/en-us/dotnet/api/microsoft.windowsazure.storage.blob.cloudblockblob.uploadfromfile?view=azure-dotnet#Microsoft_WindowsAzure_Storage_Blob_CloudBlockBlob_UploadFromFile_System_String_Microsoft_WindowsAzure_Storage_AccessCondition_Microsoft_WindowsAzure_Storage_Blob_BlobRequestOptions_Microsoft_WindowsAzure_Storage_OperationContext_

    Hope it helps you.

    Kind regards.

  • Community Member Profile Picture
    on at

    Thank you so much for your answers!

    Now, when I am trying to pass FileMode.Open in second parameter, I am receiving the following error.

    screen2.jpg

  • Verified answer
    Mea_ Profile Picture
    60,286 on at

    FileMode.Open  is c# syntax, in AX you need to write FileMode::Open

  • Community Member Profile Picture
    on at

    Thank you, file upload is working now.

  • Community Member Profile Picture
    on at

    I am currently working on upload a file to azure storage. What is the best practice of saving this account name and account key?

    Where should i store these pair so it's secure at the same time I can set this for each environment?

  • Mea_ Profile Picture
    60,286 on at

    I would say "azure key vault", you can find in AOT classes that already work with it, so you can build your own base on them.

  • Community Member Profile Picture
    on at

    Thanks. I found key vault page.

  • Prasad.V Profile Picture
    185 on at

    What are the best practices and recommendations with file upload to Azure blob storage? Is this a preferred integration approach? Can you please help me understand. Thank you.  

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans