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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Server failed to authenticate request. Make sure value of Authorization header

(1) ShareShare
ReportReport
Posted on by 22

//in d365fno

[Control("Button")]

class Download

{

public void clicked()

{

super();

new Browser().navigate(LoaneeDocumentsTable.PassportFileURL);

}

}

{

public void clicked()

{

FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;

if (result && result.getUploadStatus())

{

LoaneeDocumentsTable.PassportFileURL = result.getDownloadUrl();

//store url into table field

info( LoaneeDocumentsTable.PassportFileURL);

}

}

}

i am getting this error on web browser in local VM. I want to download the file in system.

 

I have the same question (0)
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    It's a pity that you didn't tell us where your code is failing, but I'm guessing it's when calling navigate() in Download.clicked().
     
    To me, the whole idea of storing the temporary storage URL is wrong, because it's temporary. It expires after some time and can't be used anymore.
     
    (Moved from Dynamics AX forum.)
  • AM-09080902-0 Profile Picture
    22 on at
    thank you Martin for the answer. yes you are right. then how can i download the file from url. 
  • Martin Dráb Profile Picture
    237,801 Most Valuable Professional on at
    Do you mean that you want to get the file contents to store it in a persistent storage (e.g. as a record attachment)? If so, you can use File::UseFileFromURL(result.getDownloadUrl()) to get the file contents as a data stream.
  • Verified answer
    AM-09080902-0 Profile Picture
    22 on at
    For downloading file, its clicked method in download class.
     [Control("Button")]
       class Upload
       {
          
           public void clicked()
           {
               FileUploadTemporaryStorageResult result = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
               if (result && result.getUploadStatus())
               {
           
                   FormButtonControl _control = any2Object(this) as FormButtonControl;
                   LoaneeDocumentsTable _loaneeDocsTable =   _control.formRun().dataSource(FormDataSourcestr(LoaneeDocuments_Files,  LoaneeDocumentsTable)).cursor() as loaneedocumentstable;
             
                   
                   _loaneeDocsTable.PassportFile = Binary::constructFromMemoryStream(result.openResult()).getContainer();
                   if(_loaneeDocsTable.PassportFile)
                   {
                       _loaneeDocsTable.PassportFileName = result.getFileName();
                       _loaneeDocsTable.PassportDocTypeId = result.getFileId();
                       _loaneeDocsTable.passportFileURL = result.getDownloadUrl();
                       System.IO.Stream fs = File::UseFileFromURL(result.getDownloadUrl());
               
                       System.IO.StreamReader sReader = new System.IO.StreamReader(result.openResult());
                       // Set file contentn string
                       str  fileContent = sReader.ReadToEnd();
                       _loaneeDocsTable.PassportFileRead = fileContent;
                       LoaneeDocumentsTable_ds.research(true);
                       info(result.getDownloadUrl());
                   }
               }
           
           }
       }
       [Control("Button")]
       class Download
       {
          
           public void clicked()
           {
               super();
               FormButtonControl _control = any2Object(this) as FormButtonControl;
               LoaneeDocumentsTable loaneeDocsTable =   _control.formRun().dataSource(FormDataSourcestr(LoaneeDocuments_Files,  LoaneeDocumentsTable)).cursor() as loaneedocumentstable;
              
               File::SendStringAsFileToUser(loaneeDocsTable.PassportFileRead, loaneeDocsTable.PassportFileName);
           
            
           }
         
       }

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans