Skip to content

Instantly share code, notes, and snippets.

@feliperohdee
Last active July 26, 2016 18:17
Show Gist options
  • Save feliperohdee/d367a56b73bf5bbaa164ed21c0e6449c to your computer and use it in GitHub Desktop.
Save feliperohdee/d367a56b73bf5bbaa164ed21c0e6449c to your computer and use it in GitHub Desktop.
AWS.config.credentials = {
accessKeyId: '{accessKeyId}',
secretAccessKey: '{secretAccessKey}'
};
let bucket: any = new AWS.S3({
params: {
Bucket: 'smallorange-local'
}
});
Observable.from(files)
.mergeMap((file: IFile) => {
return Observable.create((subscriber: Subscriber < IFile > ) => {
bucket.upload({
Key: file.name,
ContentType: file.type,
Body: file,
ACL: 'public-read'
}, (err, data) => {
if (err) {
return subscriber.error(file);
}
subscriber.next(file);
subscriber.complete();
});
});
}, null, this.props.concurrency)
.subscribe(
(file: IFile) => {
this.setState({
files: _.reject(this.state.files, file)
}, () => {
toastr.success(`The image ${file.name} was uploaded.`);
});
},
(file: IFile) => {
toastr.error(`The image ${file.name} could not be uploaded.`)
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment