2

I have a Django REST API, that has a model with logo tag in it, which is a file (ImageField). How should the curl command look this way. I tried this way, but it never worked for me:

curl -vX POST http://127.0.0.1:8000/client/ -d test.json --header "Conten-Type: application/json" -F "logo=@Downloads/trello.png"

1 Answer 1

4

Unfortunately JSON does not support uploading binary files, that is currently limited to multipart requests. If you do not need to send nested data, and you are not locked to JSON, I'd recommend using that.

A workaround is to create a new view for uploading files, separate from the view that requires JSON. It won't work in all situations, and will require a two step process, but it also isolates your issue.

The other option is to create (or find) a custom field which will support JSON uploads, typically using base64 encoded strings.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.