actionUploadFile.js 496 B

123456789101112131415161718
  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
  11. ? { Authorization: "Bearer " + localStorage.authToken }
  12. : {},
  13. body: fd,
  14. }).then((res) => res.json())
  15. )
  16. );
  17. };