Skip to main content

Notifications

Announcements

No record found.

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.

 

  • Verified answer
    AM-09080902-0 Profile Picture
    AM-09080902-0 22 on at
    Server failed to authenticate request. Make sure value of Authorization header
    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);
           
            
           }
         
       }
  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    Server failed to authenticate request. Make sure value of Authorization header
    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.
  • AM-09080902-0 Profile Picture
    AM-09080902-0 22 on at
    Server failed to authenticate request. Make sure value of Authorization header
    thank you Martin for the answer. yes you are right. then how can i download the file from url. 
  • Martin Dráb Profile Picture
    Martin Dráb 230,371 Most Valuable Professional on at
    Server failed to authenticate request. Make sure value of Authorization header
    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.)

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans