atmedia-image-uploader
v1.0.0
Published
React image uploader with drag and drop support
Downloads
2
Readme
ImageUploader
Props
handleImages
: Function to handle successful uploads. Should accept a single argument, the array of uploaded images.uploadImage
: Function to upload a single file. Should accept a single argument of a File object. Should return a promise that, when resolved, delivers a response in the shape of:{ image: { id: 1, ... } }
When rejected, it should return a response object in the shape of:
{ message: 'something went wrong' }
Usage
Download on npm: npm install atmedia-image-uploader
Sample usage:
const ImageUploader = require('atmedia-image-uploader');
function handleImages(images = []) {
this.setState({ images });
}
function uploadImage(imageFile) {
const url = '//upload.apartmenttherapy.com/upload';
const opts = {
method: 'POST',
body: new FormData()
};
return new Promise((resolve, reject) => {
fetch(url, opts)
.then(response => response.json())
.then(resolve)
.catch(reject);
});
}
ReactDOM.render(
<ImageUploader
handleImages={handleImages}
uploadImage={uploadImage}
/>,
document.querySelector('image-uploader-container');
);