nikolayneykov

Untitled

Jul 29th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // events.js
  2. const onSubmitUploadGif = (handler) => {
  3.   $(document).on('submit', '.upload-gif', handler);
  4. };
  5.  
  6. // handlers.js
  7. const handleSubmitUploadGif = async (event) => {
  8.   event.preventDefault();
  9.   try {
  10.     const formData = new FormData();
  11.     const f = $('#gif-file')[0].files[0];
  12.     formData.append('file', f);
  13.  
  14.     await uploadGif(formData);
  15.   } catch (error) {
  16.     console.error(error);
  17.   }
  18. };
  19.  
  20. // remote.js
  21. const uploadGif = async (data) => {
  22.   const response = await fetch(uploadUrl, {
  23.     method: 'POST',
  24.     body: data
  25.   });
  26.  
  27.   const result = await response.json();
  28.  
  29.   return result;
  30. };
Advertisement
Add Comment
Please, Sign In to add comment