Box API 2.0 downloading file

十年热恋 提交于 2019-12-11 04:21:34

问题


Trying to use the new API to download a file. But am getting an error (NotFound)

With the old API i downloaded fine:

wcGetFile.DownloadStringAsync(new Uri("https://www.box.net/api/1.0/download/" + auth_token + "/2111821875"));

With the new API this is my code:

wcGetFile.Headers[HttpRequestHeader.Authorization] = "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token;
        wcGetFile.DownloadStringAsync(new Uri("https://api.box.com/2.0/files/2111821875/data"));

The file does exist because if i remove the "data" from the end of my call i get the file info with no errors.

wcGetFile.Headers[HttpRequestHeader.Authorization] = "BoxAuth api_key=" + api_key + "&auth_token=" + auth_token;
        wcGetFile.DownloadStringAsync(new Uri("https://api.box.com/2.0/files/2111821875"));

According to the documentation the only difference between the info and the actual file is the 'data' part of the url. But that does not seem to work for me.


回答1:


It looks like we're experiencing a minor bug on our end that's preventing downloads. If you use 'https://www.box.com/' instead of 'https://api.box.com/' the download should work. We're working on fixing the bug right now, however!




回答2:


I'm not sure if you are still interested in the answer, but this code works well for me:

public static Task DownloadFile(string fileId, string location, string authToken) {
    var auth = string.Format("Authorization: BoxAuth api_key={0}&auth_token={1}", ApiKey, authToken);
    var uri = new Uri(string.Format("https://api.box.com/2.0/files/{0}/data", fileId));

    var client = new WebClient();
    client.Headers.Add(auth);
    return client.DownloadFileTaskAsync(uri, location);
}


来源:https://stackoverflow.com/questions/10393139/box-api-2-0-downloading-file

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