Issue with uploading file

System Information
  • Strapi Version: 4.9.0
  • Operating System: MacOS Ventura
  • Database: sqlite
  • Node Version: 16.17.1
  • NPM Version: 8.15.0
  • Yarn Version:

I’m trying to upload a file at entry creation with the REST api using these instructions:

I have the following code:

    const form = new FormData();

    const fsBlob = await blobFrom('./battle.jpg', 'image/jpg');

    form.append('files.fileObject', fsBlob, 'battle.jpg');

    form.append('data', JSON.stringify({name: 'assetname'}));

    const response2 =
        await fetch('http://localhost:1337/api/assets', {
          method: 'post',
          body: form,
          headers: {
            Authorization: axiosOptions.headers.Authorization

    const data = await response2.json();

but that code results in a 400 error, with the message “fileType must be defined”

The file type is specified on the blob creation but it’s not clear to me exactly where else it needs to be provided.

Note that I’m also using the strapi-provider-upload-google-cloud-storage package. I confirmed that the package is working when uploading through the admin GUI.

Figured out I needed to add a fileType property on this line:

form.append(‘data’, JSON.stringify({name:, fileType: asset.fileType}));