Image Uploader Scripting API
Functions
uploadfilter.h File Reference

Functions

bool PostUpload (ScriptAPI::UploadTaskUnion taskUnion, int reserved)
 
bool PreUpload (ScriptAPI::UploadTaskUnion taskUnion, int reserved)
 

Detailed Description

Upload filter script

Functions of this script are being called for each upload task and for each child task (e.g. file upload, thumbnail upload, url shortening)

Since
version 1.3.2

Example:

function PreUpload(taskUnion, reserved) {
if (taskUnion.type() == "TypeFile") {
local task = taskUnion.getFileTask();
local ext = GetFileExtension(task.getFileName());
if ( ext.tolower() == "png" ) {
local displayName = ExtractFileNameNoExt(task.getDisplayName());
local tempName = GetTempDirectory() + displayName + "_" + GetCurrentThreadId() + "_" + random()%50000 + ".png";
if ( CopyFile(task.getFileName(), tempName, true) ) {
task.setStatusText("Optimizing png...");
task.addTempFile(tempName);
local process = Process("optipng.exe", true);
process.setArguments([tempName]);
process.setHidden(true);
process.start();
local exitCode = process.waitForExit();
if ( exitCode == 0 ) { // Success
task.setFileName(tempName);
task.setDisplayName( displayName +".png")
} else {
WriteLog("error", "Optipng returned code " + exitCode);
return false;
}
} else {
WriteLog("error", "Cannot copy file to " + tempName);
return false;
}
}
}
return true;
}
function PostUpload(task, reserved) {
return true;
}
string GetCurrentThreadId()
int random()
void WriteLog(string type, string message)
string ExtractFileNameNoExt(string fileName)
string GetTempDirectory()
bool PostUpload(ScriptAPI::UploadTaskUnion taskUnion, int reserved)
bool PreUpload(ScriptAPI::UploadTaskUnion taskUnion, int reserved)

Function Documentation

◆ PostUpload()

bool PostUpload ( ScriptAPI::UploadTaskUnion  taskUnion,
int  reserved 
)

This function is called after upload, but child tasks (url shortening, thumbnail upload) of this task can be still running

◆ PreUpload()

bool PreUpload ( ScriptAPI::UploadTaskUnion  taskUnion,
int  reserved 
)

This function is called before upload

Returns
true - success, false - error (will abort upload)