Last active
July 26, 2016 18:17
-
-
Save feliperohdee/d367a56b73bf5bbaa164ed21c0e6449c 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
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