cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Content-Type setting for downloading using dropbox api v2

Content-Type setting for downloading using dropbox api v2

Anoop_Brijmohun
Helpful | Level 6

Good-day, 

im busy trying to write a simple app to download files from dropbox.

im a newbie to mobile dev and asistance would be appricated.

 

im am receiving this error when downloading.

Dropbox.Api.BadInputException: Error in call to API function "files/download": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded".
 Expecting one of "text/plain", "text/plain; charset=utf-8", "application/octet-stream", "application/octet-stream; charset=utf-8".

 

 var aHttpClient = new HttpClient();
                aHttpClient.DefaultRequestHeaders.Add("Content-Type", "application/octet-stream; charset=utf-8");
                var aDorpboxConfig = new DropboxClientConfig("ApplicationName") { HttpClient = aHttpClient };

                
                using (var dbx = new DropboxClient("Key_Here", aDorpboxConfig))
                {
                    
                    Dropbox.Api.Files.DownloadArg dargs = new Dropbox.Api.Files.DownloadArg(content.Path + "/" + content.Name) ;

                                  

                    using (var response = await dbx.Files.DownloadAsync(dargs))
                    {
                        var file = await response.GetContentAsStringAsync();
                       
                    }
                }
1 Accepted Solution

Accepted Solutions

Re: Content-Type setting for downloading using dropbox api v2

Anoop_Brijmohun
Helpful | Level 6
8 Replies 8

Re: Content-Type setting for downloading using dropbox api v2

DBX_Robert
Dropboxer

There does not appear to be a need for a custom HTTP client in the sample code you have provided.  Is the custom HTTP client necessary, or can your code function without one?

The .NET SDK does not require a custom HTTP client in order to function, nor do you need to explicitly set the Content-Type header.  Our .NET SDK will automatically create an HTTP client and set the appropriate headers for each API.

Re: Content-Type setting for downloading using dropbox api v2

Anoop_Brijmohun
Helpful | Level 6
Hi Robert, the reason I'm trying to add in the HTTP header is due to the "Bad HTTP content-type" message I am receiving... hence I thought I needed to specify one...

Any ideas or even a sample code extract I could try of one that works

Thanks

Re: Content-Type setting for downloading using dropbox api v2

DBX_Robert
Dropboxer

I am able to run the following C# sample from our .NET tutorials page.  It assumes a file named "file.txt" in the root folder of your Dropbox account.

 

using System;
using System.Threading.Tasks;
using Dropbox.Api;

namespace sampleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var task = Task.Run((Func<Task>)Program.Run);
            task.Wait();
        }

        static async Task Run()
        {
            using (var dbx = new DropboxClient("<OAuth Token>"))
            {
                using (var response = await dbx.Files.DownloadAsync("/file.txt"))
                {
                    Console.WriteLine(await response.GetContentAsStringAsync());
                }
            }
        }
    }
}

 

If you are doing this on mobile, are you using a framework like Xamarin?

 

Re: Content-Type setting for downloading using dropbox api v2

Anoop_Brijmohun
Helpful | Level 6

Hi

I am using Xamarin Forms.

I receive this error 


Error in call to API function "files/download": Bad HTTP "Content-Type" header: "application/x-www-form-urlencoded".
Expecting one of "text/plain", "text/plain; charset=utf-8", "application/octet-stream",
"application/octet-stream; charset=utf-8".

 

at this stage

 

 using (var response = await dbx.Files.DownloadAsync("/Test.PDF"))

Re: Content-Type setting for downloading using dropbox api v2

DBX_Robert
Dropboxer

That is the line of code I would expect to be throwing the error based on the information you've shared.

Your issue appears to be very similar to https://www.dropboxforum.com/t5/API-Support-Feedback/Xamarin-DropBox-APi-HTTP-400-Bad-request-on-Dow....

Given that the code sample works in a standard .NET project, but does not in a Xamarin project, Xamarin is likely adding additional logic that is modifying the Content-Type header in this use case.  There is little we can do to help in this situation as we do not provide support for Xamarin issues with the official Dropbox .NET SDK.  One place to possibly find additional help could be the Xamarin forums.

Re: Content-Type setting for downloading using dropbox api v2

Anoop_Brijmohun
Helpful | Level 6

thanks for the support 

will follow up with Xamarin

 

thanks again

Re: Content-Type setting for downloading using dropbox api v2

Anoop_Brijmohun
Helpful | Level 6

Re: Content-Type setting for downloading using dropbox api v2

redth
New member | Level 2

Please post any issues with the Xamarin binding here: https://github.com/xamarin/xamarincomponents

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    redth New member | Level 2
  • User avatar
    Anoop_Brijmohun Helpful | Level 6
  • User avatar
    DBX_Robert Dropboxer
What do Dropbox user levels mean?
Need more support?