Hi,
    
    Yes, you can use Elemental to access the html5 FileAPI. I'm using it in 
my personal project.
    See the file in attachement, a utility class of file api I created in 
my project. Feel free to use it (*if it works for you* ;)).    

    Hope this is helpful. 

Le mardi 12 février 2013 10:28:30 UTC+1, membersound a écrit :
>
> Hi,
>
> can I make use of the new Elemental (
> https://developers.google.com/web-toolkit/articles/elemental) to have 
> access to the HTML5 FileAPI?
> Are there any examples yet? Is that yet possible?
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


package com.seanchenxi.gwt.webrtc.client.file;

import java.util.logging.Logger;

import com.google.gwt.core.client.JavaScriptObject;
import elemental.client.Browser;
import elemental.dom.DOMException;
import elemental.html.DOMFileSystem;
import elemental.html.Entry;
import elemental.html.EntryCallback;
import elemental.html.ErrorCallback;
import elemental.html.FileError;
import elemental.html.FileSystemCallback;
import elemental.html.StorageInfoErrorCallback;
import elemental.html.StorageInfoQuotaCallback;
import elemental.html.VoidCallback;
import elemental.html.Window;
import elemental.js.html.JsFileError;
import elemental.js.util.Json;


public class FileUtilities {

    private final static Logger log = Logger.getLogger(FileUtilities.class.getName());

    public static void newFileSystem(int type, final double size, final FileSystemCallback successCallback, final ErrorCallback errorCallback){
        final int storageType = (type != Window.PERSISTENT || type != Window.TEMPORARY) ? Window.TEMPORARY : type;
        Browser.getWindow().getWebkitStorageInfo().requestQuota(storageType, size, new StorageInfoQuotaCallback() {
                    @Override
                    public boolean onStorageInfoQuotaCallback(double grantedQuotaInBytes){
                        Browser.getWindow().webkitRequestFileSystem(storageType, size, successCallback, errorCallback);
                        return true;
                    }
                }, new StorageInfoErrorCallback() {
                    @Override
                    public boolean onStorageInfoErrorCallback(DOMException error){
                        log.severe("onStorageInfoErrorCallback:\n" + Json.stringify((JavaScriptObject)error));
                        return errorCallback.onErrorCallback(Json.parse("{\"code\":" + FileError.QUOTA_EXCEEDED_ERR+"}").<JsFileError>cast());
                    }
                }
        );
    }

    public static void getFile(DOMFileSystem fileSystem, String name, EntryCallback successCallback, ErrorCallback errorCallback) {
        getFile(fileSystem, name, false, successCallback, errorCallback);
    }

    public static void getFile(DOMFileSystem fileSystem, String name, boolean createIfNotExist, EntryCallback successCallback, ErrorCallback errorCallback) {
        fileSystem.getRoot().getFile(name, Json.parse("{\"create\": "+createIfNotExist+"}"), successCallback, errorCallback);
    }

    public static void removeFile(DOMFileSystem fileSystem, String name,final VoidCallback successCallback, final ErrorCallback errorCallback) {
        getFile(fileSystem, name, new EntryCallback() {
            @Override
            public boolean onEntryCallback(Entry entry){
                entry.remove(successCallback, errorCallback);
                return true;
            }
        }, new ErrorCallback() {
                    @Override
                    public boolean onErrorCallback(FileError error){
                        successCallback.onVoidCallback();
                        return true;
                    }
                });
    }

    public static void createFile(final DOMFileSystem fileSystem, final String name, final EntryCallback successCallback, final ErrorCallback errorCallback, boolean override) {
        //Delete file if exists first.
        if (override) {
            removeFile(fileSystem, name, new VoidCallback() {
                @Override
                public void onVoidCallback(){
                    getFile(fileSystem, name, true, successCallback, errorCallback);
                }
            },errorCallback);
        } else {
            getFile(fileSystem, name, override, successCallback, errorCallback);
        }
    }
}

Reply via email to