writeFile
If you try to create a file-writing function, you'll run into a few problems. Imagine this process:
- Try to write a file with addFile.
- If the file doesn't exist and everything goes smoothly, you're done.
- If the file DOES exist, then you have to overwrite it.
- Then you have to ask for over-write confirmation.
- If okay, you have to delete the old file and upload the new file.
- However, what if something happens after the delete? In an ideal situation, you'd back up the original file, upload the new file, and if everything goes smoothly, THEN you delete the old file.
writeFile does ALL of that, with just one function call. All you have to supply is the data and a handler at the very end of the whole thing.
jpal.writeFile(file,data,handler);
file is the file to write.
data is the data to upload.
handler is a function that will receive an object parameter so you can determine status.
Example:
function checkWrite(result) {
if (result.uploaded && result.uploaded=='w00t') alert('Success!');
else alert(result.error);
}
jpal.writeFile('test.txt','ABCDEF',checkWrite);
Comments (0)
You don't have permission to comment on this page.