Box: Apply Watermark to File

Box: Apply Watermark to File

Box: ファイルに電子すかし適用

This item applies watermark to the specified file on Box.

Auto Step icon
Basic Configs
Step Name
Note
Configs for this Auto Step
conf_OAuth2
C1: OAuth2 Setting *
conf_FileId
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 creating and sharing a link to a file with an electronic watermark applied, it will not possible to download or preview watermarked files at the shared location (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 auto step


function main(){
    const oauth2 = configs.getObject("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 {AuthSettingWrapper} oauth2  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}`;
    }
}

    
Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading