Created
April 23, 2020 15:39
-
-
Save MEGApixel23/15158ea30a4c2fd3482fbdda8c994522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const upload (url) => { | |
const parts = url.split('?'); | |
const extractedFilename = parts[parts.length - 2]; | |
const filename = extractedFilename ? `${i}_${extractedFilename}` : `${i}.pdf`; | |
const key = `document-groups-documents/${docFolder}/${filename}`; | |
const response = await axios({ | |
url, | |
method: 'get', | |
responseType: 'stream', | |
}); | |
if (response.status !== 200) { | |
return false; | |
} | |
const pass = new PassThrough(); | |
const uploadPromise = s3.upload({ | |
Bucket: bucket, | |
Key: key, | |
Body: pass, | |
ContentType: response.headers['content-type'], | |
}).promise(); | |
response.data.pipe(pass); | |
return uploadPromise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment