- From: Garrett Smith <dhtmlkitchen@gmail.com>
- Date: Sat, 8 Aug 2009 09:53:51 -0700
- To: WebApps WG <public-webapps@w3.org>
- Cc: arun@mozilla.com
In glancing at some of the methods in FileAPI, I noticed some coding errors. It seems you've made an assignment in an "if" statement and assigned the result to window.status. I've annotated these with comment "(GS)". First, an overview explanation: http://dev.w3.org/2006/webapi/FileUpload/publish/FileAPI.xhtml#dfn-getAsDataURL |... If the call is successful, implementations MUST | call the callback function with a string argument | that is a valid data URL [RFC2397], and with a SUCCESS | error code on the FileError object... What is a SUCCESS error code? It sounds like SUCCESS is a "status" code that would not be an error. I also understood from your prior post that the errorHandler parameter was gone, yet I still see that in the example code below. I do not know why the callback takes two parameters instead of one. The "status code" and a "getData" method could be designed as properties of one object. Here is your simple code review:- | // Sample code in JavaScript | // Obtain fileList from <input type="file"> using DOM | | var file = fileList.files.item(0); | if (file) | { | // ... Make asynchronous call | | file.getAsDataURL(handleURL); | | } | | // ... |// (GS) What is the second parameter "error"? | function handleURL(fileAsDataURL, error) | { | | if(fileAsDataURL) | { | | // xhr.send(fileAsDataURI); | // Could also construct img src=fileAsDataURL | | } | else | { | // (GS) best to keep this on local Variable object, | // not assigning to window.status. | status = error.errorCode; | // (GS) Do not perform assignment expression in "if" | // statements. | if(status = error.NOT_READABLE_ERROR) | { | dump("File Not Readable"); | // Use another asynchronous getter | } | } |} Regards, Garrett
Received on Saturday, 8 August 2009 16:54:32 UTC