cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We want to hear from you. What do you use Dropbox for?
Close

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: 
Highlighted

Download any file as a Stream using C# SDK

Explorer | Level 3

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
Highlighted

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

Dropboxer
Dropboxer

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
Highlighted

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

Dropboxer
Dropboxer

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.

Highlighted

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

Explorer | Level 3

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.

Highlighted

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

Dropboxer
Dropboxer

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

Polls
Do you know how to organize your files and folders?
<b>We have created a guide on folder best practice, so you can get organized now <a href="https://www.dropboxforum.com/t5/Business-Tips-tricks/Folder-structure-best-practice/m-p/428456#M39"><u>check it out here</u></a>.</b>

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?