Search code examples
curlbox-apiboxapiv2

How to use cURL to download files from Box file picker URL


I am using the Box file picker in my web application to send a JS object of info. based upon the file that is chosen in the widget. In the object, part of what is returned is a URL that is valid for 15 minutes. This URL allows you to view and download the file. I am trying to utilize cURL to download the file but it doesn't seem to be working. I'm wondering if I'm missing a step in the process.

Here is a screenshot of the object that is returned successfully from the file picker widget: enter image description here

And here is my cURL attempt to download the file utilizing that same URL in the command line: enter image description here

Here is my code for the file picker widget (I've replaced the client ID with hashes):

 <div id="box-select" data-link-type="shared" data-multiselect="true" data-client-id="#########"></div>
 <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
 <script type="text/javascript" src="https://cdn01.boxcdn.net/js/static/select.js"></script>
 <script>
 $(document).ready(function() {
  var boxSelect = new BoxSelect();
  // Register a success callback handler
  boxSelect.success(function(response) {
    console.log(response);
  });
  // Register a cancel callback handler
  boxSelect.cancel(function() {
    console.log("The user clicked cancel or closed the popup");
  });
  });
  </script>

Please let me know if I'm missing something in the configuration to get this working. Thank you for the help!


Solution

  • You configured Box file picker to give you shared link type, which is a link accessible for other Box users, through the browser, depending on permissions.

    If you want a download link that can be used by anyone (valid for 15 minutes) you need a direct link type. So change first line of you file picker code to data-link-type="direct", and you should get much longer URL, that you can use with curl.

    https://developer.box.com/v2.0/docs/the-box-file-picker#section-configuration-options