Skip to content

Incorrect error message "...send your media file under the following key: 'media'." using .set_bytes #8

@mikowals

Description

@mikowals

Calling client.set_bytes(binaryImage) was leading to the error response:

Error: Sightengine error: Please make sure you encode your form data with the 'multipart/form-data' encoding and send your media file under the following key: 'media'.

I eventually fixed it by providing a string as a second argument to .set_bytes. I attempted this solution from reading the definition of set_bytes and realising it may require the filename as a second argument.

If the missing filename is the cause of the error, then I expect set_bytes to throw an error explaining it is required. The documentation and examples should also be updated with the filename argument.

For anyone landing here with the same issue my working code is:

import Sightengine from 'sightengine'
sightengine(SIGHT_ENGINE_API_USER, SIGHT_ENGINE_API_SECRET)
  .check(['nudity'])
  .set_bytes(binaryImage, 'filename')
  .then(function(res) {...})
  .catch(function(e) {...})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions