Support `FormData` #20

ForbesLindesay opened this Issue Jul 12, 2013 · 8 comments


None yet

5 participants


Posting FormData can be done using something like:

  var fd = new FormData()
  fd.append('image', file)
  var req = new XMLHttpRequest()
  req.onload = function () {
    callback(null, req.responseText)
  req.onerror = callback'post', '')
  req.setRequestHeader('Authorization', 'Client-ID ' + clientID)

However, I can see know way of handling FormData using the built in http module.

(see substack/node-browserify#439)


@ForbesLindesay take a look at mikeal/request. It does what you need with FormData, and has several nice examples.


That's a server side library though, last I checked it wouldn't run on the client, and even if it does run on the client, requireing FormData on the client seems insane since it's already there.

What I'd like would be something where you could say:

var request = http.request(options)

on the client.


OK, what I'm doing is using it to upload images to imgur. I ended up with: on the server and on the client.

What I'm saying is I'd like to be able to have the one file look something like:

var FD = FormData || require('form-data')
var hyperquest = require('hyperquest')
var concat = require('concat-stream')

module.exports = post
function post(file, clientID, callback) {
  var fd = new FD()
  fd.append('image', file)
  var headers = fd.getHeaders()
  headers.Authorization = 'Client-ID ' + clientID
  var req ='', {headers: headers})
  req.on('error', callback)

  //not sure what this API call should look like

  req.pipe(concat(function (res) { callback(null, res) }))

has there been any work to support piping xhr2 files/buffers/etc into the request?

Ran into this headache recently and it breaks in Firefox.


@ForbesLindesay did you ever figure out how to get hyperquest working with FormData?


no, I'm just using browser APIs for making requests on the browser. Helps keep the bundle small since I don't need node streams on the client anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment