Android resumable upload to Google Drive -


i testing drive api android upload file can show uploaded progress , able resume upload if fails (files size > 30 mb.)

with following questions: uploading downloading of large size file google drive giving error, upload progress listener not fired (google drive api) able upload progress , mention resumable uploads. however, don't see code looks upload error , resume logic, if kill application , "resume" upload, starts beginning.

this code:

public class drivescreen extends basedriveactivity {     private drive service;     private context context;     @override     public void onconnected(bundle connectionhint) {         super.onconnected(connectionhint);         context = this;          //https://stackoverflow.com/questions/17429798/usingoauth2-deprecated         googleaccountcredential credential = googleaccountcredential.usingoauth2(this, arrays.aslist(drivescopes.drive_file));         credential.setselectedaccountname("accountnamehere");         service = new drive.builder(androidhttp.newcompatibletransport(), new gsonfactory(), credential).build();         uploadfile();     }      public void uploadfile() {         asynctask<void, long, string> task = new asynctask<void, long, string>() {             java.io.file filecontent;             filecontent mediacontent;             com.google.api.services.drive.model.file body;             com.google.api.services.drive.model.file file;             private progressdialog mdialog;             long mfilelen;              @override             protected void onpreexecute() {                 // todo auto-generated method stub                 super.onpreexecute();                 mdialog = new progressdialog(context);                 mdialog.setmax(100);                 mdialog.setmessage("uploading ");                 mdialog.setprogressstyle(progressdialog.style_horizontal);                 mdialog.setprogress(0);                 mdialog.setbutton("cancel", new onclicklistener() {                      @override                     public void onclick(dialoginterface arg0, int arg1) {                         // todo auto-generated method stub                      }                 });                 mdialog.show();             }              class fileuploadprogresslistener implements mediahttpuploaderprogresslistener {                  @override                 public void progresschanged(mediahttpuploader uploader) throws ioexception {                     log.d("percent ", string.valueof(uploader.getprogress()));                     switch (uploader.getuploadstate()) {                     case initiation_started:                         system.out.println("initiation started");                         break;                     case initiation_complete:                         system.out.println("initiation completed");                         break;                     case media_in_progress:                         system.out.println("upload in progress");                         system.out.println("upload percentage: " + uploader.getprogress());                         mdialog.setprogress((int) (uploader.getprogress()*100));                         break;                     case media_complete:                         system.out.println("upload completed!");                         break;                     case not_started:                         system.out.println("upload not started!");                         break;                     }                 }             }              @override             protected string doinbackground(void... arg0) {                 try {                     file folder = environment.getexternalstoragepublicdirectory(                             environment.directory_pictures                         );                     file upload_file = new file(folder, "filepathhere");                     filecontent = new file(folder, "filepathhere");                     mfilelen = filecontent.length();                      inputstreamcontent mediacontent2 = new inputstreamcontent("application/zip", new fileinputstream(upload_file));                     mediacontent2.setlength(upload_file.length());                     body = new com.google.api.services.drive.model.file();                     body.settitle(filecontent.getname());                     body.setmimetype("application/zip");                     //string parentid = null;                     //int x = files.list.setq("mimetype = 'application/vnd.google-apps.folder' , title = 'sharehim'");                     //body.setparents(arrays.aslist(new parentreference().setid(uploadfile.getfilehostfolderid())));                        files.insert minsert = service.files().insert(body, mediacontent2);                     if(mfilelen > 5 * 1024 * 1024)                     {                         mediahttpuploader uploader = minsert.getmediahttpuploader();                         uploader.setdirectuploadenabled(false);                         uploader.setchunksize(mediahttpuploader.minimum_chunk_size);                         uploader.setprogresslistener(new fileuploadprogresslistener());                         file = minsert.execute();                         if (file != null) {                          }                     }                     else {                         minsert.execute();                     }                 } catch (userrecoverableauthioexception e) {                     system.out.println("login error");                     log.d("error", "not login " + e);                 } catch (ioexception e) {                     e.printstacktrace();                 }                 return null;             }               protected void onpostexecute(string result) {                 mdialog.dismiss();             };         };         task.execute();     } } 

now, uploading chunks, how can resume upload last chunk sent. first impression after watching google drive talks on youtube resumable upload handled automatically, doesn't seem case.

am approaching wrong way? worth considering using drivesyncadapter upload file alternative? (sorry bad code, test)

it looks using java rest-ful api. if use android-specific api, handled you. hand on file, , api resumable upload appropriate. see creating files.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -