Build with the Virtru Developer Hub

It's Your Data. Protect It. Control It. Everywhere.

Try the Demo          Learn More     

How to Encrypt and Upload a File to S3

const Virtru = require('virtru-sdk');
const AWS = require('aws-sdk');

 * Example showing how to encrypt and write a file to S3.
 * This example assumes you've installed the aws-sdk module and set up your AWS
 * credentials file. For more information, see:
 * Example usage: 
 *   node sample.js $(cat ~/.virtru/appId) hello.txt my-s3-bucket
 * If your bucket is configured for static website hosting you'll be able to 
 * open up Secure Reader directly from the object link.
 * (e.g.,
const email = process.argv[2];
const appId = process.argv[3];
const localFilename = process.argv[4];
const bucketName = process.argv[5];

// Initialize the Virtru and S3 clients.
const client = new Virtru.Client({email, appId});
const s3 = new AWS.S3();
// Derive the object key to use by appending .html for easy browser support.
const key = `${localFilename}.html`;
const encryptParams = new Virtru.EncryptParamsBuilder()
// The returned stream can be passed directly to s3.upload().
client.encrypt(encryptParams).then(ct =>
 s3.upload({Body: ct, Bucket: bucketName, Key: key, ContentType: 'html/text'}, onComplete));

function onComplete(err, data) {
  console.log(`${localFilename} encrypted and uploaded to S3 as ${key}`);

How to Encrypt and Upload a File to S3

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.