cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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: 

Xamarin.DropBox.APi - HTTP 400 (Bad request) on DownloadAsync

Xamarin.DropBox.APi - HTTP 400 (Bad request) on DownloadAsync

nzmike
Explorer | Level 3
Go to solution

Hi,

I have the following code in a static helper class which works perfectly in a Windows UWP app:

public static DropboxClient dbxClient { get; private set; }

......

public static async Task<string> DownloadFile(string filePath, string fileName, string accessToken)
{
            string output = null;

            try
            {
                if (dbxClient == null)
                    dbxClient = new DropboxClient(accessToken);

                if (dbxClient != null)
                {
                    var downloadResponse = await dbxClient.Files.DownloadAsync(filePath + fileName);
                    var content = await downloadResponse.GetContentAsStringAsync();
                    DebugInfo += $"{filePath} downloaded - revision {downloadResponse.Response.Rev}";
                    output = content;
                }
                else
                    throw new Exception("DownloadFile: DropBox client not authenticated");

            }
            catch (Exception ex)
            {
                Exception = ex;
                output = ex.Message;
            }

            return output;
        }

Now I want to convert the app I created in UWP to Android  so I copied it into my new Xamarin.Forms app and replaced the usual Dropbox.API NuGet package with Xamarin.DropBox.Api, but when I run the code I get this message:

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".

I have googled this and searched on this forum but (so far) can't find anything relevant - can someone please let me know what I'm doing wrong?  DropBoxClient seems to want a content-type (which is fair enough) but there does not seem to have any way to actually specify that from what I can see in the DropBoxClient properties and methods available.

 Thanks in advance for any help offered.

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

The Dropbox API does require one of a certain set of Content-Type values for download calls like this. The official Dropbox.Api library (i.e., the official Dropbox API v2 .NET SDK) does automatically set a valid Content-Type, so you don't need to do that yourself when using it. 

It sounds like when you switch to Xamarin and the Xamarin.Dropbox.Api library, something is overriding it and setting an incorrect Content-Type. I'm afraid we can't offer help with those though, as they're made/maintained by a third party. You may be better served contacting the Xamarin maintainers or asking on a Xamarin forum.

View solution in original post

5 Replies 5

Greg-DB
Dropbox Staff
Go to solution

The Dropbox API does require one of a certain set of Content-Type values for download calls like this. The official Dropbox.Api library (i.e., the official Dropbox API v2 .NET SDK) does automatically set a valid Content-Type, so you don't need to do that yourself when using it. 

It sounds like when you switch to Xamarin and the Xamarin.Dropbox.Api library, something is overriding it and setting an incorrect Content-Type. I'm afraid we can't offer help with those though, as they're made/maintained by a third party. You may be better served contacting the Xamarin maintainers or asking on a Xamarin forum.

nzmike
Explorer | Level 3
Go to solution

Thanks Greg - I thought the Xamarin DropBox APi was a variant on the official but as it's not I'll ask over on the Xamarin forums.

luismiguelsi
New member | Level 2
Go to solution

Hello, 

I have the same problem. did you solve it?.

thanks

nzmike
Explorer | Level 3
Go to solution

No, I still have not fixed this but I have not really been looking at it due to other projects.  However, I am now back trying to work out why I get his error - but so far no luck.

If I find out i will post here - but if you have solved the problem could you please post your answer here?

AwesomeHacks
New member | Level 2
Go to solution

Hi Guys,

 

I too was stuck at this problem, as i wanted a free data storage and retreval for my Xamarin.forms App.

Here are some of the points that i understood with this problem:

1. Xamarin is not yet supported by DropBox yet.

2. The above problem is in the autosetting done by xamarin frame work at the backend.

Ans:

Right click on android project of your solution > Select PropertiesDropBox.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Goto Android Options> Select Advance Properties

Drop2.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Select HttpClient implementation as Default ( this would be by default set to Android).DropBox.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

and Select  SSL/TLS implementation as Native TLS 1.2+.

Now compile and run your Xamarin.Forms application, it should work like a charm.

Refer this link as to understand why this changes were done Here.

 

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    AwesomeHacks New member | Level 2
  • User avatar
    nzmike Explorer | Level 3
  • User avatar
    luismiguelsi New member | Level 2
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?