Skip to content

Commit

Permalink
return base64 string only
Browse files Browse the repository at this point in the history
  • Loading branch information
meinstein committed Jan 11, 2018
1 parent 51cf9b3 commit 8d5ffeb
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/ImagePicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import { loadFile, loadImage } from '../utils'
import { FilePicker } from '..'

/**
* ImageInput returns a base64-encoded string of the
* given image. It does NOT return a native file object
* like the generic FilePicker component, but rather wraps it
* and then loads the image into HTMLImageElement in order
* to validate the dimensions of the uploaded image.
*/
* ImageInput returns a base64-encoded string of the
* given image. It does NOT return a native file object
* like the generic FilePicker component, but rather wraps it
* and then loads the image into HTMLImageElement in order
* to validate the dimensions of the uploaded image.
*/

class UploadImage extends React.Component {

static propTypes = {
children: PropTypes.node.isRequired,
onChange: PropTypes.func.isRequired,
Expand All @@ -33,18 +32,18 @@ class UploadImage extends React.Component {

try {
const dataUrl = await loadFile(file)
const img = await loadImage(dataUrl, dims)
await loadImage(dataUrl, dims)

// pass base64-encoded string to onChnage handler
onChange(img)
onChange(dataUrl)
} catch (err) {
// pass err message to onError handler
onError(err.message)
}
}

render() {
const {children, ...unused} = this.props
const { children, ...unused } = this.props
// pass our own onChange handler here and
// use the user-provided onChange handler above in _handleImg
Reflect.deleteProperty(unused, 'onChange')
Expand Down

0 comments on commit 8d5ffeb

Please sign in to comment.