Upload file to Azure storage with Aspose.Words REST API authentication issue

Hello,

When we call the Aspose File Upload API to initially upload a file it returns an Authentication error. This issue only happens when we call it from an Azure hosted application. It works OK when run locally. I have confirmed that we are passing in the correct App SID and App Key so am unsure why it would fail to authenticate only when run from the azure cloud.

Exception Details:

  • Error Description: The remote server returned an error: (401) Unauthorized.
    {“Message”:“Authentication failed!”}
  • Error Type: Com.Aspose.Storage.ApiException

Can you please confirm if it is intended to be able to call the Aspose Cloud Web Service from the Azure Cloud and if there is any specific setup which is needed to make it work?

Thank you

@mstride

Thank you for contacting Aspose Support.

This issue only happens when we call it from an Azure hosted application.

Am I right in my assumption that you are calling Apose Cloud API from Azure hosted application. You are not using Azure as third-party storage. In other words, you are trying to upload a file to Aspose Cloud Storage not on Azure Storage.

Can you please confirm if it is intended to be able to call the Aspose Cloud Web Service from the Azure Cloud and if there is any specific setup which is needed to make it work?

Yes, it should work and you are not supposed to do any specific setup.

We also offer OAuth 2.0 authentication along with URL Signing. The cURL example to upload file to Aspose Cloud Storage using OAuth authentication would look as follows:

// First get Access Token
// Get App Key and App SID from https://dashboard.aspose.cloud/
curl -v "https://api.aspose.cloud/oauth2/token" \
-X POST \
-d 'grant_type=client_credentials&client_id=0B17F60A-6D69-426B-9ABD-79F35A6E9F7B&client_secret=53b8b19adffa41a3e87dbbd8858977ae' \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

// Upload File to Aspose Cloud Storage
curl -v "https://api.aspose.cloud/v1.1/storage/file?path=testfile.txt" \
-X PUT \
-T testfile.txt \
-H "Content-Type: multipart/form-data" \
-H "Accept: application/json" \
-H "Authorization: Bearer x1gyQElrKoW-N27FXiuBUhJO0KcUr50ZUcm6NQrAwR2aI5EDXtdABOjuWUp_bHRV-OUBE1hFNsnMm_KiTRRFFpdLh7YzJqLFTkMlJfioA8N81bQmT5kUg936W1tpe0H1cDccBeV08UIvvsT6mqewZ3DiG9OrEDRgb3fx31OuRY8oyVv62vQI1JKSJAGEl0Qy6Dnr_DsR5rdVUeCy8En6gBMd_gj2KgJFAr6awG3S4ufQHTgGVadt-wpBQ4aPwImLASSWfPTv7JonlVT0_-I69zjVHqmO8moAEDsDMvdY39eM1Se_fQMBIve0-gWYrHrikThMo7r4jtY_h9JCXQBr1H1NtHwEPIVXvh7NREAxzALMFsl7y_4OWw1vMRI0O3oYNXVjvwkwhR6_rUr4nYl-xEaFeciKknk8YifKqkpksPlZWUiN"

I hope this helps.

Thank you,

We are using the Aspose Cloud SDK with .NET. Anyway it looks like the filename we had was incorrect. We had 7b1ce71795d14ebb937441ed6d4142cb_empty…docx for the filename (2 dots). I’m still not certain why this worked locally and not on cloud but ensuring we have a correct filename seems to have resolved the issue.

@mstride

We hope you are using our revamped Aspose.Words Cloud SDK for .NET. The SDK can be installed via NuGet as follows:

nuget install Aspose.Words-Cloud

@mstride

We would like to update you that the latest API Version V4.0 of Aspose.Words Cloud API includes its own storage API methods, so now you do not need to use Aspose.Storage API for the purpose.

var localName = "C:/Temp/02_pages.docx";
var remoteName = "Document1.docx";
var folder = "Temp";
var storageName="production";
var fullName = Path.Combine(folder, remoteName);
var request = new Aspose.Words.Cloud.Sdk.Model.Requests.UploadFileRequest(System.IO.File.OpenRead(localName), fullName, storageName);
wordsApi.UploadFile(request);