App User downloads multiple files at a time
We want to allow our app users to download more than one file at a time through Box-UI-widget.
Our app uses Content Explorer currently and allows users to download single file at a time.
Introducing Content Picker would allow users to select multiple files, but there is no download action button to operate on the selected files or folders.
Box had said that custom code is necessary for this objective whether we use Content Explorer or Content Picker.
Has anyone solved for app users downloading more than one file at a time? Our application uses Rails.
Thanks!
Colin
-
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:
- Set up your content picker to listen to the choose event (info here). This will allow you to capture that JSON payload.
- 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).
- 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
-
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
-
Thank you -- I will look into explorer's preview events.I have two more concerns here:
- 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."
- 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 -
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
サインインしてコメントを残してください。
コメント
5件のコメント