Support Topics Documentation Slack YouTube Blog

REST Upload File Problem

(Avery Choke) #1

I am trying to upload a picture through the REST API, following the documentation but I keep having error. This is what my problems are. Note: I performed this through Swift.

  1. I followed the documentation and set Content-Type: application/json. However, I am getting error 400 and after reading the error message I noticed that I need to use Content-Type: multipart/form-data.
  2. I changed to multipart/form-data and try to upload my image, but I am having a problem where the result returned is not a JSON file and the upload didn’t work at all.
  3. So I tried to upload a simple .txt file as shown in the example, and it returned me the result JSON file with the result url. However, the problem is that when I look into the Console, the file is not inside the folder at all. I tried to open the result url but it gave me Error 6007, Resource not found.
  4. So I tried to use the curl as shown in the example, and it works. But then, writing it through the code in Swift doesn’t work. I believe the Swift code is correct.
    Is it a problem with Swift itself, Backendless REST API, or is there something I did wrong or missed? I checked the permission everything is default. Thank you.

(Avery Choke) #2

I tested this using the Postman app for manual REST. And the same problem occurred. Could there be a problem with Backendless API?

(Avery Choke) #3

Finally I know the problem. I know a lot of people is having this problem as well. So I will give the answer myself. Notice that the Content-Type is multipart/form-data. This means that the file that you are planning to upload (picture/text file/etc) must be in the format of multipart/form-data. You can do explicit conversion yourself or use third party library like Alamofire. Cheers!!!