I am attempting to add an attachment to an Asana task.
My JSON request body is as follows:
request_body = {
"data" => {
"file" => "@#{attachment.tempfile}"
}
}
I receive this output on the POST:
error: file: File is not an object
The "attachment" variable is a regular rails form attachment.
Any ideas?
-----EDIT-----
For anyone looking in the future, I figured it out using the Faraday gem. Here is the code I used:
connection = Faraday.new(:url => @uri) do |conn|
conn.response :logger
conn.request :multipart
conn.request :url_encoded
conn.basic_auth(@api_key, '')
conn.adapter :net_http
end
payload = { :file => Faraday::UploadIO.new(file, file_type) }
response = connection.post(@uri, payload)
return response
Ah, that's actually the one case you can't use JSON - you need to do a form-encoded upload, otherwise you're just trying to set the "file" parameter to the string "@tmpfile.txt" (or what have you).
I'm not familiar with rails specifically but the real question here is "how to post a file upload from Rails" - the Asana endpoint here works exactly like all other form uploads.