Pregunta

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.

¿Fue útil?

Solución

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!

Otros consejos

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);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top