Peter Pik Peter Pik - 1 year ago 166
Node.js Question

Uploading a url image to s3 aws

I'm trying to upload an image but i keep getting an error with the export of the secret and key

SyntaxError: Unexpected reserved word
. here is what i've tried

first i require the aws dependencies.

var AWS = require('aws-sdk');
export AWS_ACCESS_KEY_ID='key'
export AWS_SECRET_ACCESS_KEY='secret'
AWS.config.region = 'eu-west-1';ยจ

Upload image function

function uploadImage(url, title) {

request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {

var s3Bucket = new AWS.S3( { params: {Bucket: 'bucket'} } )
var data = {Key: title + "-" + Math.floor( / 1000), Body: body};
s3Bucket.putObject(data, function(err, data){
if (err) {
console.log('Error uploading data: ', data);
} else {
console.log('succesfully uploaded the image!');



run the function

uploadImage("http:/imageUrl", "test");

Answer Source

export is not a correct way to add an environmental variable in node.js.

You should either

var AWS = require('aws-sdk');

or, most likely, pass them to your script as

export AWS_ACCESS_KEY_ID='key'
node server.js

export is a reserved js word.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download