Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fileChangedHandler(e) {
  2.     e.preventDefault();
  3.     const file = e.target.files[0];
  4.     const isImage = file.type.indexOf('image') > -1;
  5.     if (file && isImage) {
  6.       const reader = new FileReader();
  7.  
  8.       reader.onloadend = () => {
  9.         const image = new Image();
  10.         image.src = reader.result;
  11.         image.onload = () => {
  12.           const resizedDataUrl = resizeImage(image, 1280);
  13.           this.uploadHandler(file.name, resizedDataUrl);
  14.         };
  15.       };
  16.       reader.readAsDataURL(file);
  17.     }
  18.   }
  19.   uploadHandler(filename, file) {
  20.     return api.postData('/images', file, filename)
  21.       .then((response) => {
  22.         response = JSON.parse(response);
  23.         // React-specific stuff
  24.         this.setState({
  25.           id: response.id,
  26.           thumbUrl: response.thumbUrl,
  27.           url: response.url,
  28.           currState: 'complete',
  29.         });
  30.       });
  31.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement