Forum Xamarin.Forms

Xamarin Forms and DropBox - get " Bad HTTP Content-Type" error when downloading file

Hi all,

I was sure I'd posted this question to the forums already but my profile does not show any questions having been posted so I'm trying again.

Ok, so I have an existing Winsdows10 UWP app called "PassPort" which uses v2 of the standard DropBox API to upload and download data files without issue. Now I want to get this app working on my Android phone (Nokia 8 running Android 8.1) so I created a XF project, copied my download/upload code over to the main project and added Xamarin.Dropbox API from NuGet. I can create a valid Dropbox session, get basic stuff like user details etc but when I try to download a file I get 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".

Now I cannot see anywhere in the Xamarin.Dropbox API that allows me to specify a content-type for the header so I am really stuck!

Here is the code I'm using to download the file - this works perfectly every time with the standard Dropbox API.

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

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

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

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

        return output;
    }

Now I'll admit this is my first Xamarin Forms project so perhaps I'm doing something wrong but the app runs perfectly Ok on the "Android_accelerated_c86_Oreo" 8.1 emulator until I try to run the above code...so does anyone know how I can resolve this?

Please don't tell me to post over on the official Dropbox forums - I did that and they replied that as it's a Xamarin specific version of the Dropbox API, I would need to ask over here on the Xamarin forums.

Best Answers

  • AnubhavRanjanAnubhavRanjan INXamarin Team Xamurai
    Accepted Answer

    @nzmike I think your issue is related to this https://github.com/dropbox/dropbox-sdk-dotnet/issues/77
    Can you try and check there?

  • nzmikenzmike Member ✭✭
    Accepted Answer

    @SteveGraddy - thanks so much for this, I have finally got my app working!!! I gave up on it months ago because I could never get the GIT repo to compile (to fix the bug) but using this exact code (and adding the reference to System.Net) it worked first time. It seems hard to believe this has still not been fixed in the SDK but at last now we have a valid workaround.

    Thanks again - really appreciate you taking the time to post here and help me solve this. :-)

Answers

  • AnubhavRanjanAnubhavRanjan INXamarin Team Xamurai
    Accepted Answer

    @nzmike I think your issue is related to this https://github.com/dropbox/dropbox-sdk-dotnet/issues/77
    Can you try and check there?

  • nzmikenzmike Member ✭✭
    Thanks so much for that - that's the exact problem I'm having. So the guy over there said he had recompiled the code - is this just a matter of getting a git repo of the xamarin Dropbox library, making his change and recompiling? If so where do I find the library?
  • nzmikenzmike Member ✭✭

    Thanks - I think I can use this so will download and have a go at compiling it.

  • nzmikenzmike Member ✭✭
    Accepted Answer

    @SteveGraddy - thanks so much for this, I have finally got my app working!!! I gave up on it months ago because I could never get the GIT repo to compile (to fix the bug) but using this exact code (and adding the reference to System.Net) it worked first time. It seems hard to believe this has still not been fixed in the SDK but at last now we have a valid workaround.

    Thanks again - really appreciate you taking the time to post here and help me solve this. :-)

  • @SteveGraddy - still the best solution 18 months later (Visual Studio Mac). Thanks

Sign In or Register to comment.