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: 

Re: Download any file as a Stream using C# SDK

Download any file as a Stream using C# SDK

Bobby I
Explorer | Level 4
Go to solution

Hey, I'm wanting to download a file through the C# SDK, however I'm having issues when it is of the Dropbox .paper or similar cloud storage file type. I'm wanting it as a MemoryStream for my team and I to work with. Using the DropboxClient.Files.DownloadAsync, I'm given an Unsupported Type error when attempting to download a .paper / .gdoc etc, but works fine with .doc / .docx. I'm given a similar error when using the DownloadZipAsync. I saw in the docs to use Export As. Inspecting the FileMetaData.ExportInfo only contained "html" for the .paper file I was trying to download. I've looked online for a solution but am coming up empty handed. Here is a snippet of my code.

string path = myInputs.path;
MemoryStream newStream = new MemoryStream();
try
{
    var fileObject = await dropboxClient.Files.GetMetadataAsync(path);
    if (!String.IsNullOrWhiteSpace(fileObject.AsFile.ExportInfo.ExportAs))
    {
        using (var response = await dropboxClient.Files.ExportAsync(fileObject.PathLower))
        {
            (await response.GetContentAsStreamAsync()).CopyTo(newStream);
            return newStream;
        }
    }
    else
        using(var response = await dropboxClient.Files.DownloadAsync(path)){
            (await response.GetContentAsStreamAsync()).CopyTo(newStream);
            return newStream;
        }
}

What's the best way to handle universally downloading files from dropbox, regardless of file type? I would prefer to not call GetMetaDataAsync if possible to lower API calls, but it's okay if it required for checking the ExportInfo.

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

No, unfortunately the API doesn't offer the ability to request a different export type, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though. 

View solution in original post

3 Replies 3

Greg-DB
Dropbox Staff
Go to solution

You have the right idea here. As you found, some cloud files, such as Paper docs, can't be downloaded via the normal Download method. You need to use Export for those instead. 

 

You can either just try to Download the file and catch the UnsupportedFile error, at which point you would use Export instead, or you can check the file ahead of time by calling GetMetadata like you mentioned. If you do that though, you can use FileMetadata.IsDownloadable instead of checking ExportAs.

Bobby I
Explorer | Level 4
Go to solution

I see. I think I will add a catch for this as you suggested and then attempt to export it. When I was attempting to export a paper file, the ExportAs value was always html. Through the Dropbox GUI, we're able to export as Markdown, Docx, or PDF. Is it possible to change how we want it to be exported programmatically? When it is html, we get a lot of extra fluff like styling and tags, when all we are realy interested in is the content.

Greg-DB
Dropbox Staff
Go to solution

No, unfortunately the API doesn't offer the ability to request a different export type, but I'll pass this along as a feature request. I can't promise if or when that might be implemented though. 

Need more support?