sheetaki/api/file/index.js

27 lines
990 B
JavaScript
Raw Normal View History

const URL = require('url');
const do_wb = require('../../src/util');
fs = require('fs');
const AWS = require('aws-sdk');
module.exports = function (req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
const url = URL.parse(req.url, true);
2021-05-03 16:06:05 +00:00
// const s3 = new AWS.S3({ endpoint: 'http://localhost:4566', s3ForcePathStyle: true });
const s3 = new AWS.S3();
const getFile = (filename) => {
2021-05-03 16:06:05 +00:00
s3.getObject({ Bucket: 'sheetaki-test', Key: filename }, function (err, data) {
if (err) return res.status(500).send(err.message || err);
do_wb(req, data.Body, url, res);
});
}
if (!url.query.filename) return res.status(400).send("Must specify filename");
if (url.query.filename){
getFile(url.query.filename);
// fs.readFile(url.query.filename, (err, body) => {
// if (err) return res.status(500).send(err.message || err);
// do_wb(req, body, url, res);
// });
}
};