Codebase API Documentation

Ruby/Faraday - Add project file

So, you want to add a file to a project as described in File Storage and you're using Ruby and Faraday?

This is a two step process, first of all we're going to upload the file, then we're going to create a file object to link that upload with your project.

Upload the file

require 'faraday'
require 'json'

USERNAME = 'account/username'
APIKEY = 'myapikey'

connection = => "") do |builder|
  builder.basic_auth USERNAME, APIKEY
  builder.request :multipart
  builder.response :logger
  builder.adapter Faraday.default_adapter

payload = { 'files[]' =>'path/to/file', 'file_mime_type') }
response = '/upload' do |req|
  req.body = payload
  req.headers['Accept'] = 'application/json'
rtn_data = JSON.load(response.body)

token = rtn_data['uploads'][0]['identifier']

Create the project file

payload = JSON.dump({ :name => "My screenshot", :description => 'shows the broken thing', :file_upload_token => token })
response = "/#{PROJECT_PERMALINK}/files" do
  req.body = payload
  req.headers['Accept'] = 'application/json'
  req.headers['Content-Type'] = 'application/json'

You should now have a new file in the Files area of your project.