Tip: create a download link for a file
完了Hi All,
If anyone needs to create a download link for an existing file in Box you can do this by creating a "Share" using the Box API as per the guide here: https://developer.box.com/reference/put-files-id--add-shared-link/
If you include the option 'can_download' as 'true' a download_url is created, example body:
{"shared_link": {"access":"open","password":"P@ssW0rd!","unshared_at":"2021-12-31T10:53:43-08:00","permissions":{"can_download": true}}}
Example response:
{"type":"file","id":"818460444201","etag":"5","shared_link":{"url":"https:\/\/XXXXX.box.com\/s\/muitvhgewlm60e5xrtasybrepitarht6","download_url":"https:\/\/XXXXX.box.com\/shared\/static\/muitvhgewlm60e5xrtasybrepitarht6.pdf","vanity_url":null,"vanity_name":null,"effective_access":"open","effective_permission":"can_download","is_password_enabled":true,"unshared_at":"2021-12-31T10:53:43-08:00","download_count":0,"preview_count":0,"access":"open","permissions":{"can_preview":true,"can_download":true}}}
Hope this helps.
Any problems let me know and I'll try to help,
Nick
-
正式なコメント
Hey Nick,
Thanks for posting this tip.
Thanks,
Alex, Box Developer Advocate
コメントアクション -
Hello all,
I am currently attempting to take this 'download_url' and use it as a URL to pass to my own company API to then upload to our platform. But this isn't working. Making a request to that URL anonymously with curl is returning a 404 and pasting it into the browser shows that "This user is not allowed to use direct links. I guess this just confused me because I thought this would not be the case given access and can_download parameters. Thanks!
-
I don't think that the download_url is cURL compliant. I have only ever used it in a browser.
If you want to download a file that you've create a Share Link for I think you need to use the Box API again.
Something like this (fileid is the fileid created when the file was uploaded and used in the API call of the share-link):curl -i -X GET "https://api.box.com/2.0/files/<fileid>/content" -H "Authorization: Bearer <BEARER-TOKEN>" -L --output <OUTPUT.New.Filename.pdf>
Obviously the user who created the Bearer Token needs to have access to the File in Box.....so you might have to change the permissions on the File before they can download it. Or if it's the same user uploading, sharing and downloading the file then no changes to permissions are needed.
Hope this helps.
サインインしてコメントを残してください。
コメント
3件のコメント