Skip to content

Instantly share code, notes, and snippets.

@MEGApixel23
Created April 23, 2020 15:39
Show Gist options
  • Save MEGApixel23/15158ea30a4c2fd3482fbdda8c994522 to your computer and use it in GitHub Desktop.
Save MEGApixel23/15158ea30a4c2fd3482fbdda8c994522 to your computer and use it in GitHub Desktop.
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