13 November 2019

You can create input fields or use libraries like react-dropzone in React very easily. You still need to get the files from the form and send them to backend for saving. This snippet is the upload part that you can use to send files to backend using regular form "multipart/form-data" method via javascript.

Source code viewer
  1. const formData = new FormData();
  2.  
  3. // allFiles in this example are an array of files from Dropzone onDrop method.
  4. allFiles.forEach(file => formData.append('files[]', file));
  5.  
  6. fetch('/claims/addFile', {
  7. method: 'POST',
  8. body: formData,
  9. })
  10. .then(response => {
  11. // Log response from the backend server.
  12. console.log(response);
  13. });
Programming Language: ECMAScript