cordova-plugin-jc-googledrive icon indicating copy to clipboard operation
cordova-plugin-jc-googledrive copied to clipboard

Zero items in file list and 0 bytes in uploaded file

Open mbluewolf opened this issue 8 years ago • 7 comments

Hello, I installed the 1.1.0 version, running shows cordova 5.1.1 at a device with android 5.0.2

1)fileList comes with zero files (i have more than two files in the drive), called requestSync after this result and still get an empty list, after various retries it fails with Status(statusCode= Sync request rate limit exceeded, resolution=null). 2)uploadFile does end successfully, but the uploaded file contains 0 bytes each time at retries.

the test code:

mListFiles() {
    var o = this;
    var listFilesFromAppFolder = false;
    var oDisplay = o.mGetElementInsideElement(o.panel, 'divGdrvDisplay');

    var fnsuccess = function (res) {
        //the files are under res.flist;
        var files = res.flist;
        var i = 0;
        var s = '';
        for (i = 0; files.length; i++) {
            s += files[i].name + '\n';
        }
        oDisplay.innerText = files.length + " files." + '\n' + s;
    };

    var fnerror = function (err) {
        console.log(err);
        oDisplay.innerText = err;
    };

    window.plugins.gdrive.fileList(listFilesFromAppFolder,
       function (res) {
           if (res.flist.length > 0) {
               fnsuccess(res);
           } else {
               var returnFiles = true;
               window.plugins.gdrive.requestSync(returnFiles, fnsuccess, fnerror);
               oDisplay.innerText = "reqsync...";
           }
       }
       ,fnerror
    );
    oDisplay.innerText = "Reading file list...";
}


mUpload() {
    var o = this;
    var oDisplay = o.mGetElementInsideElement(o.panel, 'divGdrvDisplay');

    var fpath = cordova.file.externalDataDirectory + 'textfile.txt';

    window.plugins.gdrive.uploadFile(fpath, false,
       function (response) {
           //simple response message with the status
           var s = response.fileId;
           oDisplay.innerText = s;
       },
       function (err) {
           console.log(err);
           oDisplay.innerText = err;
       }
    );

    oDisplay.innerText = "uploading...";

}

thank you in advance...

mbluewolf avatar Apr 08 '17 10:04 mbluewolf

Do you see any errors or warnings on Android's Logcat? If yes can you list them here?

The most common reason for any action to not work is because there is something wrong with the oauth client id setup. Make sure you have correctly setup the client ids (SHA1 and app package) on the developer console.

JcDenton86 avatar Apr 09 '17 11:04 JcDenton86

Hi, i added a couple calls to log.i and collected some lines from the logcat. 1)fileList, it gets connected when calling, but i am not sure the buffer comes with the expected info. When it finds zero files i try requestsync and does the same. 2)uploadFile, i can see it is not finding the file, i use cordova-plugin-file to create textfile.txt and send the url to your code, var furl = cordova.file.externalDataDirectory ; , giving the value = "file:///storage/emulated/0/Android/data/mx.lab.apps/files/textfile.txt"

also attempted directly with "/storage/emulated/0/Android/data/mx.lab.apps/files/textfile.txt" and "/Android/data/mx.lab.apps/files/textfile.txt" results in the same.

Logcat: 04-09 21:52:20.773 I/GoogleDrivePlugin(26802): Plugin initialized 04-09 21:52:20.773 I/GoogleDrivePlugin(26802): fileList 04-09 21:52:30.883 I/GoogleDrivePlugin(26802): API client connected. 04-09 21:52:30.883 I/GoogleDrivePlugin(26802): query 04-09 21:52:31.173 I/GoogleDrivePlugin(26802): flistBuffer:com.google.android.gms.drive.MetadataBuffer@108a5b4b 04-09 21:52:31.173 I/GoogleDrivePlugin(26802): com.google.android.gms.drive.MetadataBuffer@108a5b4b 04-09 21:52:38.693 I/GoogleDrivePlugin(26802): requestSync 04-09 21:52:40.233 I/GoogleDrivePlugin(26802): query 04-09 21:52:40.253 I/GoogleDrivePlugin(26802): flistBuffer:com.google.android.gms.drive.MetadataBuffer@30a16127 04-09 21:52:40.253 I/GoogleDrivePlugin(26802): com.google.android.gms.drive.MetadataBuffer@30a16127 04-09 21:56:34.333 I/GoogleDrivePlugin(29141): Plugin initialized 04-09 21:56:34.333 I/GoogleDrivePlugin(29141): fileList 04-09 21:56:34.663 I/GoogleDrivePlugin(29141): GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{26489f0d: android.os.BinderProxy@3e6fdec2}, message=null} 04-09 21:56:34.663 I/GoogleDrivePlugin(29141): trying to resolve issue... 04-09 21:56:39.503 I/GoogleDrivePlugin(29141): API client connected. 04-09 21:56:39.503 I/GoogleDrivePlugin(29141): query 04-09 21:56:39.593 I/GoogleDrivePlugin(29141): flistBuffer:com.google.android.gms.drive.MetadataBuffer@380e841a 04-09 21:56:39.603 I/GoogleDrivePlugin(29141): com.google.android.gms.drive.MetadataBuffer@380e841a 04-09 21:56:39.603 I/GoogleDrivePlugin(29141): requestSync 04-09 21:56:40.833 I/GoogleDrivePlugin(29141): query 04-09 21:56:40.863 I/GoogleDrivePlugin(29141): flistBuffer:com.google.android.gms.drive.MetadataBuffer@780c7e6 04-09 21:56:40.863 I/GoogleDrivePlugin(29141): com.google.android.gms.drive.MetadataBuffer@780c7e6 04-09 21:56:44.263 I/GoogleDrivePlugin(29141): fileList 04-09 21:56:44.263 I/GoogleDrivePlugin(29141): query 04-09 21:56:44.293 I/GoogleDrivePlugin(29141): flistBuffer:com.google.android.gms.drive.MetadataBuffer@2b7a6fd4 04-09 21:56:44.293 I/GoogleDrivePlugin(29141): com.google.android.gms.drive.MetadataBuffer@2b7a6fd4 04-09 21:56:44.303 I/GoogleDrivePlugin(29141): requestSync 04-09 21:56:45.873 I/GoogleDrivePlugin(29141): query 04-09 21:56:45.893 I/GoogleDrivePlugin(29141): flistBuffer:com.google.android.gms.drive.MetadataBuffer@2938e8c3 04-09 21:56:45.893 I/GoogleDrivePlugin(29141): com.google.android.gms.drive.MetadataBuffer@2938e8c3 04-09 21:56:47.753 I/GoogleDrivePlugin(29141): New contents created. 04-09 21:56:47.763 E/GoogleDrivePlugin(29141): /file:/storage/emulated/0/Android/data/mx.blautek.apps/files/textfile.txt: open failed: ENOENT (No such file or directory) 04-09 21:56:48.023 I/GoogleDrivePlugin(29141): DriveId:CAESABhuIPKmo4u-UygA

mbluewolf avatar Apr 10 '17 15:04 mbluewolf

@JcDenton86 Hi, about the point 2)file uplolad, i modified one line: //Uri fPathURI = Uri.fromFile(new File(fpath)); Uri fPathURI = Uri.parse(fpath); with this it works ok.

3)if i modify the java code within the visual studio 2015 cordova project directly, it doesnt take any effect, i have to remove the plugin, modify the code outside and the install it again, is there a way to modify it directly within the IDE?

mbluewolf avatar Apr 12 '17 01:04 mbluewolf

@mbluewolf , it should work without changing this line.

Cordova uses the form file///path/to/file when you resolve a file path using the file plugin. You need to remove the whole first part (file:///) before sending it to the upload method. Your Logcat reports the path /file:/storage/em/.. which is wrong String. This is a feature that I will add to the plugin on a next update. Don't use Uri.parse because it fails on other situations.

  1. You can change the Java code directly from the below path platforms/android/src/gr/jcdenton/GoogleDrive.java

JcDenton86 avatar Apr 12 '17 06:04 JcDenton86

In this fork by @xitter https://github.com/xitter/cordova-plugin-jc-googledrive there is a fix regarding the zero items when calling the fileList method, more specifically at this line https://github.com/xitter/cordova-plugin-jc-googledrive/blob/master/android/GoogleDrive.java#L290 the filters have been altered a bit. I've been using the fork and it works great. Could not get it to work with the current build on the original repo.

stefanbc avatar Oct 13 '17 10:10 stefanbc

I'm encountering an empty list as well. My authentication flow uses cordova-plugin-googleplus and doesn't share any state with the gdrive calls.

aokj4ck avatar Oct 19 '17 21:10 aokj4ck

Looks like adding a mime-type-filter ("application/octet-stream") causes an empty result. In my case I'm uploading json files. When I remove this filter everthing looks correct. Why is setting this filter nessassary?

andelz avatar Dec 18 '17 08:12 andelz