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 (java.io.FileNotFoundException) caught when processing request: image_1.jpeg (The system cannot find the file specified)”

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

API used: https://my.plantnet.org/

My code:

import http.requests.*;

public void setup() 
{
  size(400,400);
  smooth();
  
  File img = new File("image_1.jpeg");

  PostRequest post = new PostRequest("https://my-api.plantnet.org/v2/identify/all?api-key=MY_API_KEY_REMOVED");
  post.addFile("images", img);
  post.addData("organs", "['flower']");
  post.send();
  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