Skip to content

Instantly share code, notes, and snippets.

@SavageWilliam
Created July 27, 2017 21:51
Show Gist options
  • Save SavageWilliam/d7832682db6530bfc45ff4635f2cf20c to your computer and use it in GitHub Desktop.
Save SavageWilliam/d7832682db6530bfc45ff4635f2cf20c to your computer and use it in GitHub Desktop.
Passing uploaded files into dialog
// Button with onClick to open dialog
<p className='uploadcare-button' onClick={() => { this.openUploader() }}>
Click to add images
</p>
// function to open dialog with desired settings
openUploader () {
const { imageFiles } = this.props
const files = imageFiles && // On the first upload 'flow' there are no images hence 'null' is passed in.
imageFiles.map((file) => {
return uploadcare.fileFrom('uploaded', file.cdnUrl)
})
uploadcare.openDialog(files || null, {
publicKey: '98fd1017b4e0aed32708',
imagesOnly: true,
tabs: 'file camera facebook instagram',
multiple: true
}).done((fileGroup) => {
const arrayOfFiles = fileGroup.files()
return Promise.all(arrayOfFiles).then((imageFiles) => {
this.props.updateImageFiles(imageFiles) // update uploaded files... ready to be passed into the dialog when next opened with openUploader
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment