J.P.A.L.

 

getFile

Page history last edited by Anonymous 2 yrs ago

getFile

 

Implements the API GetFile function, which returns a file and the associated meta data. getFile returns the data as parameters passed to the specified handler:

 

jpal.getFile(file,handler,metaOnly);

 

file is the name of the file to retrieve.

handler is the function that will receive the data.

metaOnly is a boolean that determines whether the function retrieves both the data and the meta data, or just the meta data. false returns both, true returns only the meta data. Optional (defaults to false).

 

The handler function may take one or two parameters. If only receiving meta data, the object containing the file header information is the only parameter. If getting both, the first parameter is still the meta data, but the second parameter is the actual file data.

 

If something goes wrong, the first parameter will have error and errCode set. ''errCode' will be equivalent to the HTTP status code.

 

Example:

 

document.write('<textarea id="txt"></textarea><br />');
document.write('File Size: <span id="filesize"></span><br />');
function processFile(meta,data) {
if (meta.errCode) { alert('Error retrieving file. Aborting.'); return; }
document.getElementById('filesize').innerHTML = meta.size;
document.getElementById('txt').value = data;
}
jpal.getFile('somefile.text',processFile);

Comments (0)

You don't have permission to comment on this page.