Last active
October 25, 2018 15:39
-
-
Save shamique/d796f3c44ef1534d19decf4a32e44426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upload(image, imageName, accessToken) { | |
return new Promise((resolve, reject) => { | |
aws.config.region = this.SYSTEM_VARIABLE.REGION; | |
aws.config.credentials = new aws.CognitoIdentityCredentials({ | |
IdentityPoolId: this.SYSTEM_VARIABLE.COGNITO_IDENTITY.IDENTITY_POOL_ID, | |
Logins: { | |
"cognito-idp.<REGION_NAME>.amazonaws.com/<USER_POOL_ID>": accessToken | |
} | |
}); | |
var s3 = new aws.S3({ | |
apiVersion: "2006-03-01", | |
params: { Bucket: this.SYSTEM_VARIABLE.S3.BUCKET_NAME } | |
}); | |
let buf = new Buffer(image, "base64"); | |
var data = { | |
Bucket: this.SYSTEM_VARIABLE.S3.BUCKET_NAME, | |
Key: imageName, | |
Body: buf, | |
ContentEncoding: "base64", | |
ContentType: "image/jpeg" | |
}; | |
s3.putObject(data, (err, res) => { | |
if (err) { | |
reject(err); | |
} else { | |
resolve(res); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment