Help with HTTP requests - POST

I need some help with rest api from Processing. I’m using HTTP Request for Processing library, but I can’t get addFile() to locate my image file. Image file is saved in data folder.

Error message received: “I/O exception ( caught when processing request: image_1.jpeg (The system cannot find the file specified)”

Library reference: HTTP-Requests-for-Processing/src/http/requests/ at master · runemadsen/HTTP-Requests-for-Processing · GitHub

API used:

My code:

import http.requests.*;

public void setup() 
  File img = new File("image_1.jpeg");

  PostRequest post = new PostRequest("");
  post.addFile("images", img);
  post.addData("organs", "['flower']");
  System.out.println("Reponse Content: " + post.getContent());
  System.out.println("Reponse Content-Length Header: " + post.getHeader("Content-Length"));
1 Like

In my opinion the error occurs in this line and has nothing to do with the post request

Are you sure the file is in the sketch directory?

please try ....File(sketchPath("image_1.jpeg"));

(Also, maybe it’s jpg or JPEG, this is not always correctly shown by Windows)

1 Like

Or use loadImage(...); instead of File

in combination with PImage img; ?

1 Like

Using sketchPath() works!
Thank you, I appreciate it.

1 Like