Upload/Store a Document

Use this endpoint to upload and store a binary document on the blockchain. The document must be located on a webserver that will provide it to the upload program.

Outcome

The result of the API is to create an asset identifying a document and storing the document on the blockchain. A document ID will be returned to the calling program that you can use to link the document to other assets.

Endpoint

https://tracapi.com/api.v2/put_doc/

Fields/Parameters

Fields/Parameter Value
auth_key Your api key "blockchain address:secret key" assigned one of the locations on your account. This will be included in the new asset record to identify the creator of the location record. Required
path The URL of the server (and subdirectories) of the location where the document is located. Required
file The file name (last part of the url) where the document is located. Required
file_hash An optional SHA256 hash of the file that will be stored in the metadata of the document. Optional
data Optional data related to the document that can be returned in a trace. Data must be formatted as a JSON object. Optional

Test it

Sample Code - PHP/Curl

<?php

$auth_key=$_POST['auth_key'];
$path=$_POST['path'];
$file=$_POST['file'];
$file_hash=$_POST['file_hash'];
$data=$_POST['data'];

//URL of the endpoint.
$url = 'https://tracapi.com/api.v2/put_doc/';

//Create an array of POST data to be sent to the endpoint.
$fields = array(
'auth_key' => $auth_key,
'path' => $path,
'file' => $file,
'file_hash' => $file_hash,
'data' => $data);

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);

//execute post
$result = curl_exec($ch);

//echo the result
echo $result;

//close connection
curl_close($ch);
?>