Get the file download link for shared folder
I have a shared folder. That link let me browse the file by ID - https://c2c.app.box.com/v/{folder}/file/{file_id}
Is it possible to get a direct link for the file downloading instead of browsing?
-
Hi , I think this might work for you:
Use this API to get the item for a shared link:
https://developer.box.com/reference/get-shared-items
This should return a folder object with the first X items in the folder.
-
I'm not getting any items from that folder when call get-shared-items:
{ "type": "folder", "id": {id}, "sequence_id": "0", "etag": "0", "name": "folder name", "created_at": "2020-05-19T09:09:17-07:00", "modified_at": "2020-05-19T15:11:33-07:00", "description": "", "size": 311087559, "path_collection": { "total_count": 4, "entries": [ { "type": "folder", "id": "0", "sequence_id": null, "etag": null, "name": "All Files" }, { "type": "folder", "id": {id}, "sequence_id": "2", "etag": "2", "name": "Clients" }, { "type": "folder", "id": [id}, "sequence_id": "0", "etag": "0", "name": "name" }, { "type": "folder", "id": {id}, "sequence_id": "0", "etag": "0", "name": "name" } ] }, "created_by": { "type": "user", "id": {id}, "name": "name", "login": "login" }, "modified_by": { "type": "user", "id": {id}, "name": "name", "login": "login" }, "trashed_at": null, "purged_at": null, "content_created_at": "2020-05-19T09:09:17-07:00", "content_modified_at": "2020-05-19T15:11:33-07:00", "owned_by": { "type": "user", "id": {id}, "name": "name", "login": "login" }, "shared_link": { "url": "https://c2c.box.com/v/name", "download_url": null, "vanity_url": "https://c2c.box.com/v/name", "vanity_name": "name", "effective_access": "open", "effective_permission": "can_download", "is_password_enabled": false, "unshared_at": null, "download_count": 0, "preview_count": 0, "access": "open", "permissions": { "can_preview": true, "can_download": true } }, "folder_upload_email": null, "parent": { "type": "folder", "id": {}, "sequence_id": "0", "etag": "0", "name": "name" }, "item_status": "active" }
Even if I call get-folders-id I'm not getting any share link for the files:
"item_collection": { "total_count": 6, "entries": [ { "type": "file", "id": {id}, "file_version": { "type": "file_version", "id": {id}, "sha1": {sha1} }, "sequence_id": "0", "etag": "0", "sha1": {sha1}, "name": "File name" },
-
my bad, I missed a step.
Step 1: convert a shared link to an item (file or folder)
curl -X GET https://api.box.com/2.0/shared_items \ -H 'Authorization: Bearer ' -H "BoxApi: shared_link=https://c2c.app.box.com/s/v2vpg8ct70..."
In your case, this will return a folder object with an ID.
{ "type": "folder", "id": "12345", "sequence_id": "0", .... }
Step 2: Use the folder ID to list the items in the folder
curl -X GET https://api.box.com/2.0/folders/12345/items \ -H 'Authorization: Bearer ' -H "BoxApi: shared_link=https://c2c.app.box.com/s/v2vpg8ct70..."
Note that we use the same BoxApi header here as we did in the previous API.
This will return the same folder object but with a list of items in the item_collection attribute.
Step 3: Keep traversing the tree
You can keep traversing the tree here for every item in the folder. So in your case, if you want to access a file with file ID 23456, you'd use:
curl -X GET https://api.box.com/2.0/files/23456 \ -H 'Authorization: Bearer ' -H "BoxApi: shared_link=https://c2c.app.box.com/s/v2vpg8ct70..."
Step 4: Download the file
Finally, to download the file, simply call the endpoint to download the content.
curl -X GET https://api.box.com/2.0/files/23456/content \ -H 'Authorization: Bearer ' -H "BoxApi: shared_link=https://c2c.app.box.com/s/v2vpg8ct70..."
サインインしてコメントを残してください。
コメント
3件のコメント