title: React Native Multipart XMLRequest - Unrecognized FormData part
body: <p>I am trying to upload some files to my website. The below code works when it's a normal API request (No attachments included). But when I try to upload a file, I keep on getting this error response: <code>"Unrecognized FormData part."</code>.</p>
  
  <pre><code>export function HTTPRequest({body = {}, url = '', method = "POST", headers = {}, attachments = [], DEBUG = false}) {
      return new Promise((resolve, reject) =&gt; {
      const attachmentsCount = Object.keys(attachments).length * 1
      const ContentType = 0 &lt; attachmentsCount ? "multipart/form-data" : "application/x-www-form-urlencoded"
  
      const submitXML = (xhrBody) =&gt; {
        let xhr = new XMLHttpRequest()
        xhr.open(method, url)
        headers["Content-Type"] = ContentType
        //headers["Accept"] = "application/json"
        for(var h in headers) {
          xhr.setRequestHeader(h, headers[h])
        }
        xhr.addEventListener('load', (res) =&gt; {
          switch(res.target.status) {
              case 200: return resolve(DEBUG ? res.target.response : JSON.parse(res.target.response))
              default: return reject(res)
          }
        }, false)
        xhr.onerror = e =&gt; reject(e)
        xhr.send(xhrBody)
      }
  
      switch(attachmentsCount) {
          case 0:
            var request = JSON.stringify(body)
            submitXML(request)
          break
        default:
          let xhrBody = new FormData()
          xhrBody.append("_photosCount", String(attachmentsCount))
          attachments.map((file, i) =&gt; {
          xhrBody.append('file', {name: file.name, src: file.src, type: file.type})
          })
          xhrBody.append('data', body)
          console.log(xhrBody);
          submitXML(xhrBody)
      }
    })
  }
  </code></pre>
  
  <p>This is the FormData Object once I tried to log it:</p>
  
  <pre><code>    0:"file"
      1: Object
      name:"FB_IMG_1498693908215.jpg"
   src:"content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F175865/ORIGINAL/NONE/1351181913"
      type:"image/jpeg"
  </code></pre>