Welcome to the new Box Support website. Check out all the details here on what’s changed.

App User downloads multiple files at a time

New post

Comments

5 comments

  • jcleblanc

    Hi ,

     

    For this one you'll indeed need a bit of custom code. Basically when you "choose" a series of files with the content picker, you'll receive a response from the Box APIs with a JSON payload to let you know what those chosen files are, something like this:

     

    [ { "type": "file", "id": "415542687401", "etag": "2", "name": "Audio.mp3", "size": 2772151, "parent": { "type": "folder", "id": "69083462919", "sequence_id": "2", "etag": "2", "name": "Preview Test Folder" }, "extension": "mp3", "permissions": { "can_download": true, "can_preview": true, "can_upload": false, "can_comment": true, "can_rename": false, "can_delete": false, "can_share": false, "can_set_share_access": false, "can_invite_collaborator": false, "can_annotate": false, "can_view_annotations_all": true, "can_view_annotations_self": true }, "path_collection": { "total_count": 2, "entries": [ { "type": "folder", "id": "0", "sequence_id": null, "etag": null, "name": "All Files" }, { "type": "folder", "id": "69083462919", "sequence_id": "2", "etag": "2", "name": "Preview Test Folder" } ] }, "modified_at": "2019-07-29T11:05:45-07:00", "created_at": "2019-03-04T15:16:01-08:00", "modified_by": { "type": "user", "id": "7503712462", "name": "Jeremy Press", "login": "jpress@boxdemo.com" }, "has_collaborations": true, "is_externally_owned": false } ]

     

    This is basically what you'll need to do:

    1. Set up your content picker to listen to the choose event (info here). This will allow you to capture that JSON payload.
    2. You will then set up a JWT application (info here) that will allow you to make requests to the Box APIs. Once that app is set up your code will authenticate the app to start making calls (info here).
    3. You will then loop through all results from step 1 and call the get file (or folder) method of the SDK you're using to download all of those files (info here).

    That will allow you to download all of the files chosen as a collection in the background.

     

    Thanks,

    Jon

    0
    Comment actions Permalink
  • colin4

    Hi   

    Thanks for the guidance. Unfortunately, we forgo the ability for users to preview files if we switch from Content Explorer to Content Picker.  Would you mind confirming this?

     

    Thanks,

    Colin 

    0
    Comment actions Permalink
  • jcleblanc

    Hi ,

     

    That's correct, you'd need to load another view with another element (e.g. preview widget) to display that content.

     

    Here's another option, the Content Explorer widget also has the ability to listen for "select" events (info here). If you integrate the Explorer with the preview widget, then use that select event you should be able to get the same data back once a user highlights a file / folder in the view.

     

    - Jon

    0
    Comment actions Permalink
  • colin4
    Thank you  -- I will look into explorer's preview events.  
     
    I have two more concerns here: 
    1. It seems a shared link must be available in order to download the selected file by API. Is that right? One is not required to download a file from content explorer. When I do enable the shared link, I get the message  "This user is not allowed to use direct links. Contact box support team."
    2. More broadly, seems if we must download to our server before sending the content to the user's browser then that essentially doubles the time it takes to download a file? 
     
    Thanks again for your responses.
     
    -Colin
    0
    Comment actions Permalink
  • jcleblanc

    Hi ,

     

    For downloading files, you won't ned a shared link, just an application with access to that user's files, then you call the download file endpoint with the ID of the file, rather than the shared link.

     

    For #2, yes it does. If you are using the content explorer element you can also embed the preview element inside it. This would allow the user to preview the content right there, then download it if the correct scope (item_download) is set. 

     

    So, in short, you can use the content explorer with all available scoped to also embed the preview element, which can allow people to preview and download one file at a time. If you want to download multiple at a time then you would have to use another app and the download endpoint to fetch all of the files, then display them in some fashion to the user.

     

    Thanks,

    Jon

    0
    Comment actions Permalink

Please sign in to leave a comment.