简体   繁体   English

使用asp.net mvc在Dropbox中下载文件

[英]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. 我正在使用asp.net mvc 4dropbox-api从我的保管箱帐户下载文件。 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, 我已经在项目中成功安装了api,并且正在按照本教程来了解其功能,但是如果我运行该程序会收到错误消息,

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. 我对api相关的作品不感兴趣,因此无法弄清楚这里有什么问题。 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 "/". Dropbox API的非根目录路径应以“ /”开头。 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". 这将导致路径“ My Folder / My File.rar”,但实际上应为“ / My Folder / My File.rar”。 So, instead, you probably want code like this instead: 因此,相反,您可能需要这样的代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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