Search code examples
curldownloadbox-api

Error 302 in downloading files Box api


Helo I am developing for Box API. I am trying to download a file. I already vardump the file and it already has a a correct url. but it will just display this

string 'HTTP/1.1 302 Found
Server: ATS
Date: Fri, 13 Mar 2015 14:41:22 GMT
Content-Length: 0
Cache-Control: no-cache, no-store
Location: https://dl.boxcloud.com/bc/4/3e0b9dd52bc17a1edaf1c263ec613202/o-EWhPXtuelO1i_6OmSS5hOgZg0uBzXTykrrTg_ayh0ZRcRIBB15yPlDHRoYjfVRpA4Ub1dxWSCzF0pTMPVbpGD2tLBCJQF8IHoOEigMbQUIrV4C5-u-ZhJzP6uAgZxDfliI3F_Vp0WxBvjIUuKFP9wqTFJLxQHpGqA9yMH_w9-MpTQzBszWjTD9AxFyamT5MxKVDu3ak3ShkzA1xDGMiOLxMPe599zxAt_e8kuNN0stjxgQwSFsVuSR8xrqMp4VTQ9MHK4Gc2qru1zJaZy804JWGhgGUTyb6ncoG3jIrknjzh8ccM9wiKmJZKWq'... (length=1521)

and its an empty blank with this error. Pls help. Thank you in advance


Solution

  • Box is redirecting you to the URL from which you can download the file content. This is the expected behavior. From the Box API documentation:

    If the file is available to be downloaded, the response will be a 302 Found to a URL at dl.boxcloud.com. The dl.boxcloud.com URL is not persistent. Clients will need to follow the redirect in order to actually download the file. The raw data of the file is returned unless the file ID is invalid or the user does not have access to it.

    Update

    You can instruct cURL to automatically follow redirects by using the -L option (see also). And here's a solution for PHP.