title: Facebook Graph API how to upload image in node.js?
body: <p>I am trying to follow this guide:</p>
  <p><a href="https://developers.facebook.com/docs/graph-api/resumable-upload-api" rel="nofollow noreferrer">https://developers.facebook.com/docs/graph-api/resumable-upload-api</a></p>
  <p>After researching how to attach multipart/form-data, as is suggested in the guide I came up with this code:</p>
  <pre><code>    const FB = require(&quot;fb&quot;)
      const fs = Npm.require(&quot;fs&quot;)
  
      FB.setAccessToken(accesstoken)
  
      const post = async () =&gt; {
          let res = await FB.api(&quot;app/uploads&quot;, &quot;post&quot;, {
              file_type: &quot;image/jpeg&quot;,
              file_length: file_length,
          })
          if (!res || res.error) {
              console.log(!res ? &quot;error occurred&quot; : res.error)
              return
          }
          const http = require(&quot;http&quot;)
          const FormData = require(&quot;form-data&quot;)
  
          const form = new FormData()
          const readStream = fs.createReadStream(imagepath)
          form.append(&quot;file&quot;, readStream)
  
          const req = http.request({
              host: &quot;graph.facebook.com&quot;,
              headers: {
                  Authorization:
                      &quot;OAuth accesstoken&quot;,
                  file_offset: 0,
                  Connection: &quot;close&quot;,
                  ...form.getHeaders(),
              },
              method: &quot;POST&quot;,
              path: &quot;/&quot; + res.id,
          })
  
          form.pipe(req, { end: true })
  
          req.on(&quot;response&quot;, function (res) {
              console.log(res)
          })
  
          return res
      }
  </code></pre>
  <p>I want to be getting the uploaded file handle, but all Im getting in the response is a huge object, that starts like this (with statusCode 200):</p>
  <pre><code>IncomingMessage {
    _readableState: ReadableState {
      objectMode: false,
      highWaterMark: 16384,
      buffer: BufferList { head: null, tail: null, length: 0 },
      length: 0,
      pipes: null,
      pipesCount: 0,
      flowing: null, ...
  </code></pre>
  <p>What am I doing wrong? Probably the way I am attaching the file. The guide doesnt state which name to give it, so I just named it &quot;file&quot;.</p>
  <p>Any help is greatly appreciated.</p>