Download a file in Dropbox using asp.net mvc

一个人想着一个人 提交于 2019-12-02 18:52:15

问题


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.


回答1:


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))


来源:https://stackoverflow.com/questions/34675472/download-a-file-in-dropbox-using-asp-net-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!