Image Uploader Scripting API: uploadfilter.h File Reference

| Image Uploader Scripting API

Functions
uploadfilter.h File Reference

## Functions

bool | PostUpload (ScriptAPI::UploadTask task, int reserved)
bool | PreUpload (ScriptAPI::UploadTask task, 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(task,reserved)
{
if ( task.type() == "TypeFile") {
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;
}

## Function Documentation

## ◆ PostUpload()

bool PostUpload | ( | ScriptAPI::UploadTask | task,
|  | 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::UploadTask | task,
|  | int | reserved
| ) |  |

This function is called before upload

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