From 857a7aa76c5c6a6a82e0b14b494188506731e303 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 16 Mar 2020 19:58:31 -0600 Subject: [PATCH] v1.0.2: improve docs and error messages --- .gitignore | 1 + README.md | 10 +++++++++- bin/s3-download.js | 7 ++++--- index.js | 4 ++-- package-lock.json | 2 +- package.json | 2 +- test.js | 2 +- 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index f25ac30..27d8299 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env +.env* node_modules .*.sw* diff --git a/README.md b/README.md index 69ea948..bf0ba34 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,14 @@ s3.set({ bucket, prefix, key, - body + body, + size }) ``` + +If the body is a stream then `size` must be set to `fs.statSync(filePath).size`, or the request will fail: + +``` +501 +NotImplementedA header you provided implies functionality that is not implemented +``` diff --git a/bin/s3-download.js b/bin/s3-download.js index bba8361..b114b3b 100644 --- a/bin/s3-download.js +++ b/bin/s3-download.js @@ -4,7 +4,7 @@ require('dotenv').config(); var env = process.env; var s3 = require('../index.js'); -var accessKeyId = env.AWS_ACCESS_KEY; +var accessKeyId = env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID; var secretAccessKey = env.AWS_SECRET_ACCESS_KEY; var region = env.AWS_REGION; var bucket = env.AWS_BUCKET; @@ -36,11 +36,12 @@ async function run() { }) .catch(function(err) { console.error('Error:'); - console.error('GET Response:'); if (err.response) { + console.error(err.url); + console.error('GET Response:'); console.error(err.response.statusCode); console.error(err.response.headers); - console.error(err.url); + console.error(err.response.body.toString('utf8')); } else { console.error(err); } diff --git a/index.js b/index.js index 2d2dff5..735e045 100644 --- a/index.js +++ b/index.js @@ -28,8 +28,8 @@ module.exports = { } */ /* - if (env.AWS_ACCESS_KEY) { - accessKeyId = accessKeyId || env.AWS_ACCESS_KEY; + if (env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID) { + accessKeyId = accessKeyId || env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID; secretAccessKey = secretAccessKey || env.AWS_SECRET_ACCESS_KEY; bucket = bucket || env.AWS_BUCKET; prefix = prefix || env.AWS_BUCKET_PREFIX; diff --git a/package-lock.json b/package-lock.json index c7acde6..89ae09a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@root/s3", - "version": "1.0.1", + "version": "1.0.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index f7fe4bf..73b3e2f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@root/s3", - "version": "1.0.1", + "version": "1.0.2", "description": "A simple, lightweight s3 client with only 2 dependencies", "main": "index.js", "files": [ diff --git a/test.js b/test.js index 6f0dceb..909754c 100644 --- a/test.js +++ b/test.js @@ -4,7 +4,7 @@ require('dotenv').config(); var env = process.env; var s3 = require('./index.js'); -var accessKeyId = env.AWS_ACCESS_KEY; +var accessKeyId = env.AWS_ACCESS_KEY || env.AWS_ACCESS_KEY_ID; var secretAccessKey = env.AWS_SECRET_ACCESS_KEY; var region = env.AWS_REGION; var bucket = env.AWS_BUCKET;