title: Post an image to Strapi programmatically with NodeJS
body: <p>This <a href="https://strapi.io/documentation/developer-docs/latest/development/plugins/upload.html#upload-files" rel="nofollow noreferrer">Upload documentation</a> is all I can find which gives a browser based example using the FormData api.</p>
  <p>All it states is that you <code>POST</code> to <code>/uploads</code> with a <code>files</code> parameter of type Buffer/Stream. Here's where I am at so far:</p>
  <pre><code>fs.readFile(filepath, (err, data) =&gt; {
      needle('post','http://localhost:1337/upload', {files: data}, {
          multipart: true,
      }).then(response =&gt; {
          console.log(response.body);
          if(response.body.data)
              console.log(response.body.data.errors)
      });
  });
  </code></pre>
  <p>The post is successful but something isn't quite right, the image is registered but missing in the media library with the name of 'files' instead of anything meaningful.</p>
  <p><a href="https://i.stack.imgur.com/S7M1Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S7M1Z.png" alt="enter image description here" /></a></p>
  <p>Example response from the post:</p>
  <pre><code>[
    {
      id: 170,
      name: 'files',
      alternativeText: null,
      caption: null,
      width: 768,
      height: 1024,
      formats: {
        thumbnail: [Object],
        large: [Object],
        medium: [Object],
        small: [Object]
      },
      hash: 'files_d98a49e7f5',
      ext: '',
      mime: 'application/octet-stream',
      size: 159.62,
      url: '/uploads/files_d98a49e7f5',
      previewUrl: null,
      provider: 'local',
      provider_metadata: null,
      created_at: '2021-06-09T17:12:52.951Z',
      updated_at: '2021-06-09T17:12:52.951Z',
      related: []
    }
  ]
  </code></pre>
  <p>I have also tried using the node module <code>form-data</code> to mimic the example provided in the documentation.</p>
  <pre><code>let form = new FormData();
  form.append('files', fs.createReadStream(&quot;./test.jpg&quot;))
  let data = form //attempt1
  let data = {files: form} //attempt2
  let data = {files: form.toString()} //attempt3
  needle('post','http://localhost:1337/upload', data, {
      multipart: true,
  })
  </code></pre>
  <p>But this generally returned 400 bad request with the following response:</p>
  <pre><code>{ id: 'Upload.status.empty', message: 'Files are empty' } 
  </code></pre>