Helper function to download a file
See original GitHub issueI suggest adding a method on the Web API to download a file from slack, symmetrical to files.upload
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Download file helper - php - Stack Overflow
I wanna download my file that i have upload to my web Im just saving the name of the file to database. My...
Read more >Download Helper — CodeIgniter 3.1.13 documentation
Generates server headers which force data to be downloaded to your desktop. Useful with file downloads. The first parameter is the name you...
Read more >download.file function - RDocumentation
The function download.file can be used to download a single file as described by url from the internet and store it in destfile...
Read more >How to download a file using Node.js? - GeeksforGeeks
Downloading a file using node js can be done using inbuilt packages or with third party libraries. Method 1: Using 'https' and 'fs'...
Read more >Download a file from the internet using the R functions ...
Then use the function download.file(url, filename) to download the file. Here, url is a string containing the URL of the file, and filename...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
i think the SDK could provide a helper function to download actual files. what i’m imagining is a function
web.helpers.fileDownload(fileId, [opts])
and the opts could allow you to specify if you want the return value to be a readable stream or a Buffer.First off, this repository is for handling the client that uses the Web API, which is produced by some lovely engineers at Slack. We have no control over what is and isn’t in the API. Nonetheless, such a method (one that downloads files) isn’t exactly possible with the Web API (can’t force a client to download something, you can only send data).
But, there is a way to do what you’re looking for: simply use an http client (such as request) to go to the file’s url (which you can get using the
files.list
method) and save the file’s response to disk.Further, there’s a special little bit of authentication you need to do in your request to get the file (using it’s
url_private
field), as specified by thefile
type documentation. Simply, there must be anAuthorization
header present in the request that’s set toBearer YOUR_TOKEN
(which may be the bot’s token or a OAuth token).Here’s an example of what all of that would look like:
I didn’t test the code, it could error. I’m also unaware of any situation in which a file doesn’t have a
url_private
field. You’ll have to do your own testing to make sure the above approach is sound (sorry). It should still be a solid basis for what you’re attempting to achieve. Good luck!