Sub uploadImage (filename As String, dir As String)
Log($"The filename is ${filename} and directory is ${dir}"$)
Dim j As HttpJob
j.Initialize("", Me)
' Create multipart file data
Dim mp As MultipartFileData
mp.Initialize
mp.Dir = dir
mp.FileName = filename
mp.KeyName = "images" ' key for the image
mp.ContentType = "image/jpeg" ' content type
' Prepare additional form fields (organs)
Dim map As Map
map.Initialize
map.Put("organs", "leaf")
' Set the API URL with your API key
Dim api_endpoint As String = $"https://my-api.plantnet.org/v2/identify/all?include-related-images=false&no-reject=false&nb-results=10&lang=en&type=kt&api-key=${API_KEY}"$
' Perform the POST request
j.PostMultipart(api_endpoint, map, Array(mp))
' Set the required headers
j.GetRequest.SetHeader("accept", "application/json")
j.GetRequest.SetHeader("Content-Type", "multipart/form-data")
' Wait for the response
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
' Parse the JSON response
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim jRoot As Map = parser.NextObject
Dim preferedReferential As String = jRoot.Get("preferedReferential")
Dim bestMatch As String = jRoot.Get("bestMatch")
Log("Prefered Referential: " & preferedReferential)
Log("Best Match: " & bestMatch)
Else
Log("Error: " & j.ErrorMessage)
End If
j.Release
End Sub