Files
POST /api/v1/files
Create Files
Upload a new file associated with the currently authenticated merchant.
betaThis API is a pre-release. Please contact KOMOJU to obtain more usage instructions before using it.
Examples
- cURL
- Node.js
- Ruby
curl -X POST https://komoju.com/api/v1/files \
-u sk_123456: \
-F "paper=@/your/local/path.jpg"
var https = require('https');
var secret_key = 'sk_123456'
var auth = 'Basic ' + Buffer.from(secret_key + ':').toString('base64');
// npm install form-data
var form_data = require('form-data');
var fs = require('fs');
var post_data = new form_data();
post_data.append(
'paper',
fs.createReadStream('/your/local/path.jpg')
);
var post_options = {
host: 'komoju.com',
port: '443',
path: '/api/v1/files',
method: 'POST',
headers: {
...post_data.getHeaders(),
'Authorization': auth
}
};
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
});
post_data.pipe(post_req);
require 'uri'
require 'net/https'
require 'json'
require 'base64'
require 'pp'
uri = URI.parse('https://komoju.com/api/v1/files')
request = Net::HTTP::Post.new('https://komoju.com/api/v1/files')
secret_key = 'sk_123456'
auth = Base64.encode64("#{secret_key}:")
request['Authorization'] = "Basic #{auth}"
form_data = [['paper', File.open('/your/local/path.jpg')]]
request.set_form form_data, 'multipart/form-data'
res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
puts res.body
{
"id": "16ugmu1gqyw4pxk8rmpkil9b6",
"resource": "file",
"filename": "path.jpg",
"size": 959505,
"mime_type": "image/jpeg",
"created_at": "2021-02-25T09:17:11Z",
"updated_at": "2021-02-25T09:17:11Z"
}
Params
Param name | Description |
---|---|
paper required |
The file to upload. Please refer to the cURL example, Node.js example or Ruby example, to see how to use this parameter to reference a file from your local file system. |
GET /api/v1/files/:id
Show Files
Show the information of an existing file.
betaThis API is a pre-release. Please contact KOMOJU to obtain more usage instructions before using it.
Examples
- cURL
- Node.js
- Ruby
curl -X GET https://komoju.com/api/v1/files/0sf3wwxqv0vbuvxhur81yyw51 \
-u sk_123456:
var https = require('https');
var secret_key = 'sk_123456'
var auth = 'Basic ' + Buffer.from(secret_key + ':').toString('base64');
var get_options = {
host: 'komoju.com',
port: '443',
path: '/api/v1/files/0sf3wwxqv0vbuvxhur81yyw51',
method: 'GET',
headers: {
'Authorization': auth
}
};
var get_req = https.request(get_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
});
get_req.end();
require 'uri'
require 'net/https'
require 'json'
require 'base64'
require 'pp'
uri = URI.parse('https://komoju.com/api/v1/files/0sf3wwxqv0vbuvxhur81yyw51')
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
secret_key = 'sk_123456'
auth = Base64.encode64("#{secret_key}:")
headers = {
'Content-Type' => 'application/json',
'Authorization' => "Basic #{auth}"
}
res = https.get(uri.path, headers)
puts res.body
{
"id": "16ugmu1gqyw4pxk8rmpkil9b6",
"resource": "file",
"filename": "path.jpg",
"size": 959505,
"mime_type": "image/jpeg",
"created_at": "2021-02-25T09:17:11Z",
"updated_at": "2021-02-25T09:17:11Z"
}