[The Cat API] Upload Image Data format error

Hello :slight_smile:

I have a problem with using image upload API right now.

image/upload

I am working on iOS (Swift) platform and using pure URLSession.

As the Cat API Postman document says I get my http header correct.

But i have a problem with sending image data.

I expected Swift would convert image to data format anyways but it returns error response as following.

{
  "message": "Invalid file data. Check you are sending the formdata.append('file', ...} format'",
  "status": 400,
  "level": "info"
}

So what i really wonder are

  1. I can choose data encoding types (utf-8, utf-16 … ascii, … etc) which one should it be?
  2. Is there any documents that describes Error messages that I am missing ?

I believe my code is ok.
Because I checked this API on postman and it gives 200 status code .
So I copied and pasted it on my iOS App but it does not work on my application :frowning: .

Please let me know if more information needed.

@jaden - good question.

You probably need to make sure the image data is being added to the FormData as the “file” field, and make sure the header[‘Content-Type’] = “multipart/form-data”

This looks like a good example for Swift/URLSession How To Upload Data To A Server: Multipart/Form-Data HTTP Requests in Swift - replacing “profilePicture” with “file”

1 Like