Coding is problem solving. The journey is part of the frustrations and joy. Sometimes, like asking for help in forums like here in Quick Answers, helps get us there. I don't do Python too, so I turn to ChatGPT to shortcut converting languages. It's far from perfect however it gives a good starting point to work the problem to get to the solution.
Here is the question I asked ChatGPT:
convert this python to powershell:
filename = f"C:\Temp\images\image_31c20dfc-5c63-4d48-bf0e-8d7e405a6743.jpg"
image_data = open(filename, "rb").read()
print("---------------------------")
#print('passing image to CPAI module')
response = requests.post("http://192.168.99.227:32168/v1/vision/detection",
files={"image": image_data}).json()
response
And here is the code that it generated:
$filename = "C:\Temp\images\image_31c20dfc-5c63-4d48-bf0e-8d7e405a6743.jpg"
$imageData = [System.IO.File]::ReadAllBytes($filename)
Write-Host "---------------------------"
$response = Invoke-RestMethod -Uri "http://192.168.99.227:32168/v1/vision/detection" -Method Post -InFile $filename -ContentType "application/octet-stream"
$response
and the explanation:
Please note that this PowerShell code uses the Invoke-RestMethod cmdlet to make the HTTP POST request, which is available in PowerShell by default. You may need to adjust the content type and headers as per your specific requirements. Also, make sure you have the necessary modules and permissions to execute this code.