ladjs/frisbee

Support multipart/form-data for file uploading?

obykoo opened this issue · 2 comments

This does not seem to support 'multipart/form-data' for file uploading?

@obykoo have you tried using form-data?

example:

import Frisbee from 'frisbee';
import FormData from 'form-data';

const form = new FormData();
form.append('a', 1);
const api = new Frisbee({
  // ... options here
});

// make a request, passing `form` as the `body` property
api.post('http://httpbin.org/post', {
  body: form
})
.then(console.log)
.catch(console.error);

if this works for you, let me know

@obykoo another note - if you're using this on the client side, you need to delete the Content-Type header per http://stackoverflow.com/a/35799817, e.g. https://github.com/crocodilejs/crocodile-node-mvc-framework/blob/development/src/assets/js/core.js#L222-L229

if ($form.find('input[type="file"]').length) {
  body = new FormData($form.get(0));
  // remove content-type header so boundary can be added for multipart forms
  // http://stackoverflow.com/a/35799817
  delete headers['Content-Type'];
} else {
  body = qs.parse($form.serialize());
}