55var debug = require ( 'debug' ) ( 'httpsnippet' )
66var es = require ( 'event-stream' )
77var MultiPartForm = require ( 'form-data' )
8+ var FormDataPolyfill = require ( 'form-data/lib/form_data' )
89var qs = require ( 'querystring' )
910var reducer = require ( './helpers/reducer' )
1011var targets = require ( './targets' )
@@ -122,7 +123,7 @@ HTTPSnippet.prototype.prepare = function (request) {
122123 // This hack is pretty awful but it's the only way we can use this library in the browser as if we code this
123124 // against just the native FormData object, we can't polyfill that back into Node because Blob and File objects,
124125 // which something like `formdata-polyfill` requires, don't exist there.
125- const isNativeFormData = ( typeof form [ Symbol . iterator ] === 'function' )
126+ const isNativeFormData = ! ( form instanceof FormDataPolyfill )
126127
127128 // easter egg
128129 const boundary = '---011000010111000001101001'
@@ -131,15 +132,19 @@ HTTPSnippet.prototype.prepare = function (request) {
131132 }
132133
133134 request . postData . params . forEach ( function ( param ) {
135+ const name = param . name
136+ const value = param . value || ''
137+ const filename = param . fileName || null
138+
134139 if ( isNativeFormData ) {
135- if ( isBlob ( param . value ) ) {
136- form . append ( param . name , param . value || '' , param . fileName || null )
140+ if ( isBlob ( value ) ) {
141+ form . append ( name , value , filename )
137142 } else {
138- form . append ( param . name , param . value || '' )
143+ form . append ( name , value )
139144 }
140145 } else {
141- form . append ( param . name , param . value || '' , {
142- filename : param . fileName || null ,
146+ form . append ( name , value , {
147+ filename : filename ,
143148 contentType : param . contentType || null
144149 } )
145150 }
0 commit comments