diff --git a/package.json b/package.json index 2893faa..ddd1ebb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@umbrellio/ucdn", - "version": "0.4.0", + "version": "0.4.1", "bin": "ucdn", "main": "index.js", "repository": "git@github.com:umbrellio/ucdn.git", diff --git a/upload.js b/upload.js index 7ff564c..bf1820e 100755 --- a/upload.js +++ b/upload.js @@ -29,23 +29,15 @@ const findFiles = directory => { const getKey = (file, root) => path.relative(root, file) -const uploadFile = (s3, config, file, key) => new Promise((resolve, reject) => { - const { bucket } = config - const stream = fs.createReadStream(file) - const basename = path.basename(file) - const params = { - Bucket: bucket, - Body: stream, - Key: key, - ContentType: mime.contentType(basename), - } - - stream.on("error", reject) - s3.send(new PutObjectCommand(params)) - .then(data => resolve(data)) - .catch(err => reject(err)) - .finally(() => stream.close()) -}) +const uploadFile = (s3, config, file, key) => { + return fs.promises.readFile(file).then(data => { + const { bucket } = config + const basename = path.basename(file) + const contentType = mime.contentType(basename) + const params = { Bucket: bucket, Body: data, Key: key, ContentType: contentType } + return s3.send(new PutObjectCommand(params)) + }) +} const upload = argv => { const config = getConfig(argv)