Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading Files #128

Open
nikolayg opened this issue Apr 26, 2017 · 3 comments
Open

Uploading Files #128

nikolayg opened this issue Apr 26, 2017 · 3 comments
Labels

Comments

@nikolayg
Copy link

Any idea/examples on how to upload a file with redux-api-middleware?

@coldfish
Copy link

For multipart sending, you can try this method in your action file:

export function uploadFile(htmlFile) {
  const data = new FormData();
  data.append('file', htmlFile);
  return {
    [CALL_API]: {
      endpoint: `${ROOT_URL}/upload`,
      method: 'POST',
      headers: {
        'Content-type': 'multipart/form-data, boundary=--abc--abc--'
      },
      body: data,
      types: [UPLOAD_BEGIN, UPLOAD_SUCCESS, UPLOAD_FAILURE],
    },
  };
}

@nason nason added the question label May 17, 2017
@mhfowler
Copy link

For us, we tried adding the Content-Type header after reading this issue and were unable to get it to work for a few hours due to our boundary not actually being ---abc--abc-- (and not realizing this at first). Perhaps the boundary in this answer was just left as a placeholder, but in case it is helpful to anyone who was confused like us, ultimately we were able to make file uploading work by not specifying the Content-Type at all, and letting the browser auto-fill the Content-Type with the correct boundary that we needed

@matymad
Copy link

matymad commented Apr 23, 2019

I have issues uploading a video file recorded with a webcam (redux-api-middleware 3.0.1).

My code:

const video = this.recordedVideo.getBlob();
const body = new FormData();
body.append("token", this.props.token);
body.append("video", video, "video." + video.type.split("/")[1]);

[RSAA]: {
    endpoint: "URL",
    method: "POST",
    body: body,
    headers: {
      "Content-type": "multipart/form-data, boundary=--abc--abc--"
    },
    types: [
      POSTULANT_VIDEO_UPLOAD,
      POSTULANT_VIDEO_UPLOAD_SUCCESS,
      POSTULANT_VIDEO_UPLOAD_FAILURE
    ]
  }

And the Request Payload is formated like this and my server is returning 502 (bad gateway):
Screen Shot 2019-04-23 at 1 17 54 PM

Any ideas of why it's happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants