Created
July 27, 2017 21:51
-
-
Save SavageWilliam/d7832682db6530bfc45ff4635f2cf20c to your computer and use it in GitHub Desktop.
Passing uploaded files into dialog
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
// 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