I'm struggling implementing a POST request with image attachment with the Julia HTTP package. In Python I can do (source from Pushover):
import requests
r = requests.post("https://api.pushover.net/1/messages.json", data = {
"token": "APP_TOKEN",
"user": "USER_KEY"
},
files = {
"attachment": ("image.jpg", open("myimage.jpg", "rb"), "image/jpeg")
})
How can I do such a file attachment in simple ways with Julia/HTTP or another Julia package?
Many thanks!
This should be the equivalent request using
HTTP.jl:The filename (
cat.jpg) and content type (image/jpeg) is inferred from theio.If you need better control, for example if you want the filename in the request to differ from the filename on disk, or if you want to manually specify
Content-Type, you can manually construct aHTTP.Multipartentry, like this:You can compare/verify the request from
HTTP.jlwith the one fromrequestsby using something likeand send the requests to
http://localhost:8080.