Added S3 experiment.

This commit is contained in:
DebaucheryLibrarian
2021-02-20 01:12:44 +01:00
parent 39e2abd80a
commit f310fec869
5 changed files with 15929 additions and 220 deletions

40
src/utils/s3.js Normal file
View File

@@ -0,0 +1,40 @@
'use strict';
const config = require('config');
const AWS = require('aws-sdk');
const fs = require('fs');
const nanoid = require('nanoid');
async function init() {
const filepath = './public/img/sfw/animals/j0iiByCxGfA.jpeg';
const endpoint = new AWS.Endpoint('s3.wasabisys.com');
const s3 = new AWS.S3({
// region: 'eu-central-1',
endpoint,
credentials: {
accessKeyId: config.s3.accessKey,
secretAccessKey: config.s3.secretKey,
},
});
try {
const data = await s3.listBuckets().promise();
const file = fs.createReadStream(filepath);
const key = `img/${nanoid()}.jpg`;
const status = await s3.upload({
Bucket: config.s3.bucket,
Body: file,
Key: key,
ContentType: 'image/jpeg',
}).promise();
console.log(data);
console.log(status);
} catch (error) {
console.log(error);
}
}
init();

View File

@@ -1,14 +1,14 @@
'use strict';
const bhttp = require('bhttp');
const http = require('./http');
const sleep = 5000;
const timeout = 1000;
async function init() {
try {
const res = await bhttp.get(`https://httpstat.us/200?sleep=${sleep}`, {
responseTimeout: timeout,
const res = await http.get(`https://httpstat.us/200?sleep=${sleep}`, {
timeout,
});
console.log(res.statusCode);
@@ -17,15 +17,4 @@ async function init() {
}
}
/*
/home/pendulum/projectx/node_modules/bhttp/lib/bhttp.js:159
err.response = response;
^
TypeError: Cannot assign to read only property 'response' of object '[object Object]'
at addErrorData (/home/pendulum/projectx/node_modules/bhttp/lib/bhttp.js:159:16)
at Timeout.timeoutHandler [as _onTimeout] (/home/pendulum/projectx/node_modules/bhttp/lib/bhttp.js:525:27)
*/
init();