actionUploadFile.js 416 B

12345678910111213141516
  1. import { actionPromise } from "./actionPromise";
  2. export const actionUploadFile = files => async dispatch => {
  3. let fd = new FormData();
  4. fd.append("photo", files);
  5. return await dispatch(
  6. actionPromise(
  7. "upload",
  8. fetch("/upload", {
  9. method: "POST",
  10. headers: localStorage.authToken ? { Authorization: "Bearer " + localStorage.authToken } : {},
  11. body: fd,
  12. }).then(res => res.json()),
  13. ),
  14. );
  15. };