[SOLVED] How to upload an image using POST API

Hokay, so, here’s what seems to be working for me:

  1. get your file (name and data)
  2. isolate and url encode the filename (somefile.jpg)
  3. base64 encode the filedata
  4. put the filename into array1[filename]
  5. put the filedata into array1[contents]
  6. put “false” into array1[private] (I haven’t tried making it private and attached to a database thing yet)
  7. put that array into array2[file] (I tried changing that but the server stopped accepting it, so apparently it has to be “file”)
  8. put anything else you need into array2[], for example “some example text” into array2[example]
  9. convert array to JSON (as required) what you end up with is something like this:
    array2={
    file={filename=file’s-name.jpg, private=false, contents=base64}
    example=some example text
    }
  10. setup your API to recognize the “file” parameter as a file and the “example” parameter as text
  11. change the headers to “Content-Type: application/json”
3 Likes