Box: Apply Watermark to File
This item applies a watermark to the specified file on Box.
Configs: Common
  • Step Name
  • Note
Configs
  • C1: OAuth2 Setting *
  • C2: File ID to apply watermark to *

Notes

  • The file ID is contained in the URL: https://{sub-domain}.app.box.com/file/(File ID)
  • Box refresh tokens have an expiration date. Use it regularly to ensure that it does not exceed the expiration. (Box: Token & URL Expiration)
  • Users authenticating in the C1: OAuth2 Setting must have a Box Enterprise user account
  • The added watermark is in the format {user email address – date, time, time zone} (e.g. “user@example.com – Jan 1, 2022, 9:00:00 AM PDT”)
  • If a password is set when ‘create a link and share, sharers will not be able to download or preview watermarked files (as of 2022-10-28)

Capture

See also

Script (click to open)
  • An XML file that contains the code below is available to download
    • box-file-watermark-apply.xml (C) Questetra, Inc. (MIT License)
    • If you are using Professional, you can modify the contents of this file and use it as your own add-on


main();
function main(){
    const oauth2 = configs.get('conf_OAuth2');
    const fileId = decideFileId();
    applyWatermark(oauth2, fileId);
}

/**
  * ファイル ID を config から読み出して出力する
  * @return {String} fileId ファイル ID
  */
function decideFileId(){
    const fileId = engine.findData(configs.getObject('conf_FileId'));
    if (fileId === '' || fileId === null) {
        throw 'File ID is blank.';
    }
    return fileId;
}

/**
  * 電子すかしを適用
  * @param {String} oauth OAuth2 設定
  * @param {String} fileId ファイル ID
  */
function applyWatermark(oauth2, fileId) {
    const jsonBody = {};
    jsonBody['watermark'] = {'imprint': 'default'};
    const url = `https://api.box.com/2.0/files/${encodeURIComponent(fileId)}/watermark`;
    const response = httpClient.begin()
        .authSetting(oauth2)
        .body(JSON.stringify(jsonBody), 'application/json; charset=UTF-8')
        .put(url);
    const status = response.getStatusCode();
    if (status !== 200 && status !== 201) { // 200: 更新, 201: 新規適用
        engine.log(response.getResponseAsString());
        throw `Failed to apply watermark. status:${status}`;
    }
}

    
%d bloggers like this: