Ant Blockchain supports notarization of basic data types and also large files. Large File Notary applies to the scenarios where you want to send files as the notary, or your notary data is too large (greater than 100 KB). To accomplish this, you can add fields indicating the type of file when configuring Data Classification.
Compared with basic data types, you need perform a few more tasks when constructing File notary data. We have provided utility classes in the SDK package. There are several steps that users must follow.
- Obtain your OSS configuration. After the Data Classification is set, you can see your OSS configuration when downloading SDK. Please copy the configurations to your own application.properties file.
- You need to initialize the utility class that supports file notary. We recommend that you perform the initialization only once after your system is launched. Then the work of file notarization would be performed automatically when you construct your notary data, the link and file hash will be saved in your transaction.
Code samples are shown below.
// load the configurations
Properties p = new Properties();
String endpoint = p.getProperty("oss.config.endpoint");
String accessKeyId = p.getProperty("oss.config.accessKeyId");
String accessKeySecret = p.getProperty("oss.config.accessKeySecret");
String bucket = p.getProperty("oss.config.bucket");
String folder = p.getProperty("oss.config.folder");
// initialize the OssUtil
OssUtil.init(endpoint, accessKeyId, accessKeySecret, bucket, folder);
- We use ChainFile to construct File notaries. Assume that we have our data classification set as shown below.
// schema.txt Definition：information of customer
String userName; // name，not null，length within 20
String birthday; // birthday, not null
String email; // email address, not null
File picture; // selfie picture
We use GuestInfoBuilder to construct the notary data as follows.
// construct a ChainFile object
ChainFile pic = new ChainFile("pic", new FileInputStream("/path_to_file/pic.img"));
// build the notary data
GuestInfoBuilder builder = new GuestInfoBuilder();
byte bizData = builder.buildUserName("Bob")
When we read the notary data, we can call the method getContent() to obtain the content of ChainFile, and call getFileName() to obtain the name of Chainfile.