简体   繁体   中英

Download a file in Dropbox using asp.net mvc

I'm using asp.net mvc 4 and dropbox-api to download a file from my dropbox account. I've successfully installed the api in my project and I'm following this tutorial to understand the functionalities but I'm getting an error if I run,

Specified argument was out of the range of valid values. Parameter name: path

Here are my codes,

    public async Task<ActionResult> DropDls()
    {
        var dbx = new DropboxClient("MY-TOKEN");
        string folder = "My Folder";
        string file = "My File.rar";

        using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))
        {
            await response.GetContentAsStringAsync();
        }

        return View();
    }

I'm noob to api related works, so can't figure it out what is wrong in here. But I need this to be done. I'll appreciate if I get some help from experts. Thanks.

Non-root paths for the Dropbox API should start with "/". Your code is:

    string folder = "My Folder";
    string file = "My File.rar";

...

    using (var response = await dbx.Files.DownloadAsync(folder + "/" + file))

That will result in a path "My Folder/My File.rar", but it should actually be "/My Folder/My File.rar". So, instead, you probably want code like this instead:

    using (var response = await dbx.Files.DownloadAsync("/" + folder + "/" + file))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM