I am trying to upload an image. this is the Curl code I received from the documentation of the website
curl -X POST
'https://my.craftar.net/api/v0/image/?api_key=123456789abcdefghijk123456789abcdefghijk'
-F "item=/api/v0/item/4fe672886ec142f6ab6d72d54acf046f/"
-F "file=@test.png"
I tried to solve it with 'net/http/post/multipart'
File.open("./test.png") do |png|
data = {"item" => "/api/v0/item/2fb8cc16002742ccbbecddc186b1e131"}
uri = URI.parse('https://my.craftar.net/api/v0/image/?api_key=09d29c3801932aab983892565e731ee3e5c0879e')
headers = { 'Content-Type' =>'application/json'}
req = Net::HTTP::Post::Multipart.new uri.request_uri,
{"file" => UploadIO.new(png, "image/png", "image.png")}.merge(data),
headers
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
res = http.request(req)
puts "result:"
puts res.body
end
I based this code on the documentation of 'net/http/post/multipart' But it doesn't work I get a lot of errors. And I can't figure out what I'm doing wrong.
Now I get an error from CraftAR
{"message": "Expected multipart/form-data; boundary=<..> content but got application/json; boundary=-----------RubyMultipartPost.", "code": "WRONG_CONTENT_TYPE"}}