Skip to content

Instantly share code, notes, and snippets.

@trevorfoskett
Created November 22, 2019 07:01
Show Gist options
  • Save trevorfoskett/32ef6e132ebfafa9d72d85f57a75d3d5 to your computer and use it in GitHub Desktop.
Save trevorfoskett/32ef6e132ebfafa9d72d85f57a75d3d5 to your computer and use it in GitHub Desktop.
Added upload functionality to the encrypt function.
async function encrypt(fileName, auth){
const encryptParams = new Virtru.EncryptParamsBuilder()
.withFileSource(`./encrypt-in/${fileName}`)
.withDisplayFilename(fileName)
.build();
ct = await client.encrypt(encryptParams);
var ctString = await ct.toString();
const drive = google.drive({version: 'v3', auth});
var fileMetadata = {
'name': `${fileName}.tdf3.html`,
parents: [folderId]
};
var media = {
mimeType: 'text/html',
body: ctString // Body of file is created with the encrypted string output above.
};
drive.files.create({
resource: fileMetadata,
media: media,
fields: 'id'
}, function (err, file) {
if (err) {
// Handle error
console.error(err);
console.log(`${fileName} - ERROR.`)
} else {
console.log(`- ${fileName}`);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment