Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fileChangedHandler(e) {
- e.preventDefault();
- const file = e.target.files[0];
- const isImage = file.type.indexOf('image') > -1;
- if (file && isImage) {
- const reader = new FileReader();
- reader.onloadend = () => {
- const image = new Image();
- image.src = reader.result;
- image.onload = () => {
- const resizedDataUrl = resizeImage(image, 1280);
- this.uploadHandler(file.name, resizedDataUrl);
- };
- };
- reader.readAsDataURL(file);
- }
- }
- uploadHandler(filename, file) {
- return api.postData('/images', file, filename)
- .then((response) => {
- response = JSON.parse(response);
- // React-specific stuff
- this.setState({
- id: response.id,
- thumbUrl: response.thumbUrl,
- url: response.url,
- currState: 'complete',
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement