All Products
Document Center

Large file notary

Last Updated: Jun 06, 2019

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.

  1. 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 file.large file configs

view large file configs

  1. 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.

  1. // load the configurations
  2. Properties p = new Properties();
  3. p.load(new FileInputStream("/path_to_file/"));
  4. String endpoint = p.getProperty("oss.config.endpoint");
  5. String accessKeyId = p.getProperty("oss.config.accessKeyId");
  6. String accessKeySecret = p.getProperty("oss.config.accessKeySecret");
  7. String bucket = p.getProperty("oss.config.bucket");
  8. String folder = p.getProperty("oss.config.folder");
  9. // initialize the OssUtil
  10. OssUtil.init(endpoint, accessKeyId, accessKeySecret, bucket, folder);
  1. We use ChainFile to construct File notaries. Assume that we have our data classification set as shown below.
  1. // schema.txt Definition:information of customer
  2. GuestInfo {
  3. String userName; // name,not null,length within 20
  4. String birthday; // birthday, not null
  5. String email; // email address, not null
  6. File picture; // selfie picture
  7. }

We use GuestInfoBuilder to construct the notary data as follows.

  1. // construct a ChainFile object
  2. ChainFile pic = new ChainFile("pic", new FileInputStream("/path_to_file/pic.img"));
  3. // build the notary data
  4. GuestInfoBuilder builder = new GuestInfoBuilder();
  5. byte[] bizData = builder.buildUserName("Bob")
  6. .buildBirthday("2000-01-01")
  7. .buildEmail("")
  8. .buildPicture(pic)
  9. .build();

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.