Download file from external server #3632
Unanswered
kuzmenko-tgn
asked this question in
Help
Replies: 1 comment 1 reply
-
Do this import Route from '@ioc:Adonis/Core/Route'
import axios from 'axios'
import fs from 'fs'
import Env from '@ioc:Adonis/Core/Env'
Route.get('/upload', async ({response}) => {
const resp = await axios(
{
method:'get',
url: `https://selectpdf.com/api/?key=${Env.get('SELECTPDF_API_KEY')}&url=http://www.extremeprogramming.org/rules/unittests.html`,
responseType: 'stream'
}
)
resp.data.pipe(fs.createWriteStream('tmp/uploads/file.pdf'))
response.header('Content-Disposition', 'attachment; filename=unittests.pdf'); // comment this if you want to display on the browser
response.type('.pdf')
return response.send(fs.readFileSync('tmp/uploads/file.pdf'))
}) I'm pretty sure that the |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I need to download file, that generated on the selectpdf.com platform. After generation of url I'm trying to use it with
response.download
- but it doesn't work for me - I'm getting error - "File not found"response.redirect().toPath(url) - doesn't work for me in case of CORSE
using axios also doesnt work for me.
const res = await axios({ method: 'get', url: url, responseType: 'stream', }) res.data.pipe(response.response)
Beta Was this translation helpful? Give feedback.
All reactions