Open liamks opened 12 years ago
I've made the file api completely asynchronous, it's much closer to the actual file api. I've updated the readme file, but the File section looks a little rough. I'd also appreciate some feedback on MacGap/Classes/Commands/File.m
regarding code quality.
Tested this on his fork and it works great for me.
+1 works
Bump, please just merge this
Bump!
I have merged this PR with master into a new branch called liamks-file-access. I'm keen for someone to have a play with this branch and write some definitive examples of how to use this stuff from the JS side, as I had some trouble making it do its thing.
As soon as I have that, I'll merge this back into master.
With this commit, developers will now be able to get a list of the absolute paths of files, after a user has selected files from
<input type=file>
or from drag and drop. With those absolute file paths text from the file, or a base64 representation of the file can be obtained (useful for images).Design decisions: WebKit's implementation of the File API is over 8,000 lines of C++ code and includes many dependencies. Fully implementing this would be extensive work. I reasoned that the most important thing, was a text representation and the base64 representation of a file. The code in this commit allows one to get those values. The File API includes the ability to get the Binary representation of a file, that can always be added later.
In the File API a base64 file is prefixed with its mime type. Mac OS X uses Uniform Type Identifiers (UTIs). I've thus added code that translate UTIs of images to mimetypes. It seems though that the base64 encoding of an image can still be displayed without the mimetype.
In the File API file access is asynchronous with events associated with the completion of a file reading. I wasn't able to get that to work unfortunately! However, I think someone with more Objective-c/WebKit experience could take this code and add that functionality. In the mean time I think this is usable.
Please test this first!!!