Converter (File to Base64String)

コンバータ (File to Base64String)

Converts file type data to Base 64 encoded string type data.

Auto Step icon
Configs for this Auto Step
conf_file
A: FILE DATA for convert (1 file only, 10MB less than) *
conf_base64String
B: STRING DATA for Base 64 converted (update) *
Script (click to open)


main();
function main(){
//// == Config Retrieving / 工程コンフィグの参照 ==
const dataId_file         = configs.get( "conf_file" );
const dataId_base64String = configs.get( "conf_base64String" );

//// == 演算 / Calculating ==
const files = engine.findDataByNumber( dataId_file );
let text = "";

if (files.size() != 1) {
  throw `File count invalid.`;
}

const file = files.get(0);

if (file.getLength() > 10485760) {
  throw `File size over.`;
}

fileRepository.readFile(file, 3145728, function(bytes) {
  text += base64.encodeToString(bytes);
});

engine.setDataByNumber( dataId_base64String, text );

}

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • An error occurs if there are zero or more than two files included in the File-type data. An error is generated if the file size exceeds 10MB.

Capture

%d