CEIP.uploadLog Member
Internal.
Syntax
object.uploadLog(file);
Arguments
Argument | Summary |
---|---|
file |
Returns
Remarks
See Also
Source Code
function ceip_uploadlog(file)
{
var self = this;
function uploadLogDone()
{
var rpl = request.responseText;
var ary;
if (!/^RESULT OK$/m.test(rpl))
{
ary = rpl.match(/^RESULT FAILED: (.*)$/m);
var err = ary && ary[1] ? ary[1] : request.status + " " +
request.statusText;
self.logEvent({type: "logger", event: "upload", result: "failed",
error: err});
addStatusMessage(getMsg(MSG_CEIP_UPLOAD_FAILED, [file.leafName,
err]));
return;
}
ary = rpl.match(/^ID ([\w.]+)$/m);
self.logEvent({type: "logger", event: "upload", result: "ok",
key: ary[1]});
addStatusMessage(getMsg(MSG_CEIP_UPLOAD_OK, file.leafName));
try
{
file.remove(false);
}
catch(ex)
{
self.logEvent({type: "logger", event: "error",
method: "uploadLogDone",
error: formatException(ex)});
}
};
function uploadLogError()
{
var err = request.status + " " + request.statusText;
self.logEvent({type: "logger", event: "upload", result: "failed",
error: err});
addStatusMessage(getMsg(MSG_CEIP_UPLOAD_FAILED, [file.leafName, err]));
};
try
{
// Make sure each file is only uploaded once per session.
if (file.leafName in this.uploadBlock)
return;
this.uploadBlock[file.leafName] = true;
// Create URL for sending data.
var uploadUrl = client.prefs["ceip.uploadUrl"];
uploadUrl += "?uid=" + client.prefs["ceip.userid"];
uploadUrl += "&fid=" + file.leafName;
// Read in file in chunks (FIXME: why?) into string for uploading.
var data = "";
var chunkSize = 10240;
var readLog = new LocalFile(file, "<");
while (readLog.inputStream.available() > chunkSize)
data += readLog.read(chunkSize);
data += readLog.read(readLog.inputStream.available());
readLog.close();
// Upload file using a simple POST request to the configured URL.
var request = new XMLHttpRequest();
request.onload = uploadLogDone;
request.onerror = uploadLogError;
request.open("POST", uploadUrl);
request.setRequestHeader("Content-Type", "application/xml");
request.send(data);
}
catch(ex)
{
var err = formatException(ex);
this.logEvent({type: "logger", event: "error", method: "uploadLog",
error: err});
addStatusMessage(getMsg(MSG_CEIP_UPLOAD_FAILED, [file.leafName, err]));
}
}