Developer API - Files

  1. File attributes
  2. List of all files
  3. Find a specific file
  4. Create a new file
  5. Update a file
  6. Delete a file

File attributes

A file have the following attributes:

Name Type Description
id Integer Record ID
name String File name
file_type String File type (Asset or Torrent)
description String File description
content String File content (binay), Base64 encoded
size Integer File size (bytes)
crc String File CRC
updated_at String Timestamp in ISO 8601 format
created_at String Timestamp in ISO 8601 format
created_by Integer User ID that created the record
created_via String Channel used to create the record (Interface or API)

List of all files

Return an array with all files.

Method and URL format

GET https://api.cloudwalk.io/{version}/files?access_token={token}

Example of use

$ curl -X GET "https://api.cloudwalk.io/v1/files?access_token=$TOKEN"
require 'net/http'

token = 'API_TOKEN'

uri = URI("https://api.cloudwalk.io/v1/files?access_token=#{token}")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri.request_uri)

res = http.request(request)

puts "Response #{res.code} #{res.message}: #{res.body}"

Example of response

{
   "pagination":{
      "page":1,
      "total_pages":1,
      "entries":2,
      "total_entries":2
   },
   "files":[
      {
         "file":{
            "id":6,
            "name":"bins.dat",
            "file_type":"asset",
            "description":"Bins",
            "size":19,
            "crc":"B446",
            "updated_at":"2015-03-02T15:49:56Z",
            "created_at":"2015-03-02T15:47:34Z",
            "created_by":1,
            "created_via":"interface"
         }
      },
      {
         "file":{
            "id":8,
            "name":"config.dat",
            "file_type":"asset",
            "description":"Config",
            "size":11,
            "crc":"416C",
            "updated_at":"2015-03-02T15:52:23Z",
            "created_at":"2015-03-02T15:52:23Z",
            "created_by":1,
            "created_via":"interface"
         }
      }
   ]
}

Find a specific file

Return the details of a specific file.

Method and URL format

GET https://api.cloudwalk.io/{version}/files/{file_id}?access_token={token}

Example of use

$ curl -X GET "https://api.cloudwalk.io/v1/files/6?access_token=$TOKEN"
require 'net/http'

token = 'API_TOKEN'

uri = URI("https://api.cloudwalk.io/v1/files/6?access_token=#{token}")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Get.new(uri.request_uri)

res = http.request(request)

puts "Response #{res.code} #{res.message}: #{res.body}"

Example of response

{
  "file":{
    "id":6,
    "name":"bins.dat",
    "file_type":"asset",
    "description":"Bins",
    "content":"MT0yCjM9NAo0PTUKNj03Cjg9OQ==",
    "size":19,
    "crc":"B446",
    "updated_at":"2015-03-02T15:49:56Z",
    "created_at":"2015-03-02T15:47:34Z",
    "created_by":1,
    "created_via":"interface"
  }
}

Create a new file

Create a new file.

Method and URL format

POST https://api.cloudwalk.io/{version}/files?access_token={token}

Example of use

$ curl -X POST "https://api.cloudwalk.io/v1/files?access_token=$TOKEN" \
-F "[email protected]" \
-F "description=CloudWalk DAT"

@file.dat is the file being registered, so in this example, there is a file called file.dat in the current directory, where the command curl is being executed.

require 'net/http/post/multipart'

token = 'API_TOKEN'

uri = URI("https://api.cloudwalk.io/v1/files?access_token=#{token}")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post::Multipart.new(uri.request_uri,
  "description" => "CloudWalk DAT",
  "&asset" => UploadIO.new(File.open("file.dat"), "text/plain", "file.dat")
)

res = http.request(request)

puts "Response #{res.code} #{res.message}: #{res.body}"

Example of response

{
  "file":{
    "id":10,
    "name":"file.dat",
    "file_type":"asset",
    "description":"CloudWalk DAT",
    "content":"YT1iCmM9ZAplPWY=",
    "size":11,
    "crc":"416C",
    "updated_at":"2015-03-02T16:30:51Z",
    "created_at":"2015-03-02T16:30:51Z",
    "created_by":1,
    "created_via":"api"
  }
}

Update a file

Update an existing file.

Method and URL format

PUT https://api.cloudwalk.io/{version}/files/{file_id}?access_token={token}

Example of use

$ curl -X PUT "https://api.cloudwalk.io/v1/files/3?access_token=$TOKEN" \
-F "[email protected]" \
-F "description=New CloudWalk DAT"
require 'net/http/post/multipart'

token = 'API_TOKEN'

uri = URI("https://api.cloudwalk.io/v1/files/10?access_token=#{token}")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Put::Multipart.new(uri.request_uri,
  "description" => "CloudWalk DAT",
  "&asset" => UploadIO.new(File.open("file.dat"), "text/plain", "file.dat")
)

res = http.request(request)

puts "Response #{res.code} #{res.message}: #{res.body}"

Example of response

{
  "file":{
    "id":10,
    "name":"file.dat",
    "file_type":"asset",
    "description":"New CloudWalk DAT",
    "content":"YT1iCmM9ZAplPWYKZz1o",
    "size":15,
    "crc":"1E15",
    "updated_at":"2015-03-02T16:42:01Z",
    "created_at":"2015-03-02T16:30:51Z",
    "created_by":1,
    "created_via":"api"
  }
}

Delete a file

Delete a file.

Method and URL format

DELETE https://api.cloudwalk.io/{version}/files/{file_id}?access_token={token}

Example of use

$ curl -X DELETE "https://api.cloudwalk.io/v1/files/10?access_token=$TOKEN"
require 'net/http'

token = 'API_TOKEN'

uri = URI("https://api.cloudwalk.io/v1/files/10?access_token=#{token}")

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Delete.new(uri.request_uri)

res = http.request(request)

puts "Response #{res.code} #{res.message}: #{res.body}"

Example of response

{}