Free Support Forum -

Uploading PDF file to Cloud Storage using Aspose.Storage REST API throws Bad request error

Hi. I’m trying to make a REST call to the storage but I get 'Bad Request – An error occurred while parse the multipart content: The file name could not have been retrieved." on the with the code example below. Any idea what I’m doing wrong?

  var client = new RestClient("");

  // OAuth request... 
  RestRequest requestOAuth = new RestRequest("/oauth2/token", Method.POST);
  requestOAuth.AddHeader("Authorization", "Basic " + client);
  requestOAuth.AddHeader("Content-Type", "application/x-www-form-urlencoded");
  requestOAuth.AddParameter("grant_type", "client_credentials");
  requestOAuth.AddParameter("client_id", "XXX");
  requestOAuth.AddParameter("client_secret", "XXX");
  IRestResponse responseOAuth = client.Execute(requestOAuth);

  // Convert the result to JSON
  JObject result = JObject.Parse(responseOAuth.Content);

  var requestStorePDF = new RestRequest("/v1.1/storage/file", Method.PUT);
  requestStorePDF.AddHeader("Authorization", "Bearer " + result.GetValue("access_token").ToString());
  requestStorePDF.AddHeader("Content-Type", "multipart/form-data");
  requestStorePDF.AddParameter("path", "test.pdf");
  requestStorePDF.AddParameter("file", "test.pdf");
  requestStorePDF.AddFile("test.pdf", "E:\\Documents\\test.pdf");
  IRestResponse responseStore = client.Execute(requestStorePDF);


Thanks for your inquiry. It seems some RestSharp related issue. The Upload file is working fine with cURL and Aspose.Storage Cloud SDK for .NET. Please install Aspsoe.Storage Cloud SDK for .NET from NuGet and try following code snippet. However, if you are interested only the use of RestSharp then please let us know, we will investigate it further.

// For complete examples and data files, please go to
// Get App Key and App SID from
var configuration = new Configuration { AppSid = MyAppSid, AppKey = MyAppKey };
StorageApi storageApi = new StorageApi(configuration);

var fileName = "test.pdf";
PutCreateRequest request = new PutCreateRequest(fileName, File.OpenRead(@"c:\Temp\" + fileName), null, null);
var response = storageApi.PutCreate(request);


As an update, please note we have released new microservice versions of Aspose Cloud APIs. These are better than older versions in terms of memory management and API structure. We have embedded Storage API methods in each API. Now there is no need to refer Aspose.Storage Cloud API in your project separately. For example, check code below, how to upload PDF file using Aspose.PDF Cloud SDK for .NET. Please feel free to contact us for any further assistance in this regard.

PdfApi pdfApi = new PdfApi(MyAppKey, MyAppSid);
string name = "4pages.pdf";

using (var file = System.IO.File.OpenRead(name))
    var response = pdfApi.UploadFile("Temp/4pages.pdf", file);