Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.
Problem
Confirm this is a Node library issue and not an underlying OpenAI API issue - [x] This is an issue with the Node library Describe the bug Since yesterday, a call to the "openai.images.edit" API throws an error: `BadRequestError: 400 Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.` The same API call worked for that last year without this error. To Reproduce Provide to images, and set the filenames to patchFn and maskFn, both files are PNGs. Call the openai.images.edit API with the following code Code snippets [code block] OS macOS 15.4 Node version Node v22.14.0 Library version openai 4.95.0
Error Output
error:
`BadRequestError: 400 Invalid file 'image': unsupported mimetype ('application/octet-stream'). Supported file formats are 'image/png'.`Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Unsupported Mimetype Error for PNG Files in OpenAI API Call
The error occurs because the Node library is not correctly identifying the mimetype of the provided PNG files, defaulting to 'application/octet-stream'. This can happen if the files are not being read correctly or if the library has a bug in handling file uploads.
Awaiting Verification
Be the first to verify this fix
- 1
Check File Read Method
Ensure that the files are being read correctly as buffers or streams. Use the 'fs' module to read the files and confirm their mimetype.
javascriptconst fs = require('fs'); const patchFn = fs.readFileSync('path/to/patch.png'); const maskFn = fs.readFileSync('path/to/mask.png'); - 2
Set Correct Mimetype
Explicitly set the mimetype when uploading the files to the API. This can help the library recognize the files as PNGs.
javascriptconst formData = new FormData(); formData.append('image', patchFn, { filename: 'patch.png', contentType: 'image/png' }); formData.append('mask', maskFn, { filename: 'mask.png', contentType: 'image/png' }); - 3
Update OpenAI Library
Ensure you are using the latest version of the OpenAI library, as this may contain bug fixes related to file handling.
bashnpm install openai@latest - 4
Test API Call
After making the above changes, test the API call again to confirm that the error no longer occurs.
javascriptconst response = await openai.images.edit({ image: patchFn, mask: maskFn }); console.log(response);
Validation
Confirm that the API call executes successfully without throwing the 'unsupported mimetype' error. Check the response to ensure it contains the expected output.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep