Artem Kalantai
04/29/2021, 12:39 PMRoss Coundon
04/29/2021, 12:41 PMreturn await new Promise
return new Promise
should be sufficientArtem Kalantai
04/29/2021, 12:41 PMArtem Kalantai
04/29/2021, 12:42 PMRoss Coundon
04/29/2021, 12:44 PMArtem Kalantai
04/29/2021, 12:45 PMRoss Coundon
04/29/2021, 12:45 PMArtem Kalantai
04/29/2021, 1:13 PMRoss Coundon
04/29/2021, 1:13 PMRoss Coundon
04/29/2021, 1:13 PMArtem Kalantai
04/29/2021, 1:14 PMArtem Kalantai
04/29/2021, 1:15 PMArtem Kalantai
04/29/2021, 1:15 PMconst s3 = new AWS.S3({
accessKeyId: /* Bucket owner access key id */,
secretAccessKey: /* Bucket owner secret */,
sessionToken: `session-${cuid()}`
})
Ross Coundon
04/29/2021, 1:16 PMArtem Kalantai
04/29/2021, 1:16 PMRoss Coundon
04/29/2021, 1:17 PMArtem Kalantai
04/29/2021, 1:18 PMFrank
Artem Kalantai
04/29/2021, 5:35 PMArtem Kalantai
04/29/2021, 5:36 PMArtem Kalantai
04/29/2021, 5:37 PMconst downloadFromGoogleDrive = async (authToken, file) => {
const credentials = {
accessKeyId: '',
secretAccessKey : ''
};
AWS.config.update({credentials: credentials, region: 'us-east-1'});
const s3 = new AWS.S3();
return fetch(`<https://www.googleapis.com/drive/v2/files/${file.id}?alt=media&source=downloadUrl>`, {
method: 'GET',
headers: {
"Authorization": 'Bearer ' + authToken
}
}).then((response) => {
if (response.ok) {
return response;
}
return Promise.reject(new Error(
`Failed to fetch ${response.url}: ${response.status} ${response.statusText}`));
})
.then(response => response.buffer())
.then(buffer => (
s3.putObject({
Bucket: 'fanpoint-content',
Key: 'testUser/image.jpg',
ContentType: 'image/jpeg',
Expires: 100,
Body: buffer,
}).promise()
));
}
Artem Kalantai
04/29/2021, 5:37 PMArtem Kalantai
04/29/2021, 5:38 PMFrank
Frank
const credentials = {
accessKeyId: '',
secretAccessKey : ''
};
AWS.config.update({credentials: credentials, region: 'us-east-1'});
Artem Kalantai
04/29/2021, 5:42 PMArtem Kalantai
04/29/2021, 5:43 PMFrank
default
AWS credentials you configured in your termimalArtem Kalantai
04/29/2021, 5:44 PMFrank
Artem Kalantai
04/29/2021, 5:44 PMArtem Kalantai
04/29/2021, 5:45 PMArtem Kalantai
04/29/2021, 5:46 PMArtem Kalantai
04/29/2021, 5:46 PMArtem Kalantai
04/29/2021, 5:48 PMArtem Kalantai
04/29/2021, 5:49 PMFrank
Frank
Ross Coundon
04/29/2021, 5:51 PMconst downloadFromGoogleDrive = async (authToken, file) => {
const credentials = {
accessKeyId: '',
secretAccessKey : ''
};
AWS.config.update({credentials: credentials, region: 'us-east-1'});
const s3 = new AWS.S3();
const response = await fetch(`<https://www.googleapis.com/drive/v2/files/${file.id}?alt=media&source=downloadUrl>`, {
method: 'GET',
headers: {
"Authorization": 'Bearer ' + authToken
}
})
if (!response.ok) {
throw Error(`Failed to fetch ${response.url}: ${response.status} ${response.statusText}`)
}
const buffer = response.buffer();
return s3.putObject({
Bucket: 'fanpoint-content',
Key: 'testUser/image.jpg',
ContentType: 'image/jpeg',
Expires: 100,
Body: buffer,
}).promise()
}
Artem Kalantai
04/29/2021, 5:57 PMArtem Kalantai
04/29/2021, 5:58 PM