I'm trying to do an automated upload of large files to Google drive from my local computer using:
MY CODE
public final void copyFileGoogle(String fPath, String folderIDParent, String fName) throws IOException {
Drive driveService = GoogleDriveUtils.getDriveService();
File fileMetadata = new File();
fileMetadata.setName(fName);
fileMetadata.setParents(Collections.singletonList(folderIDParent));
java.io.File filePath = new java.io.File(fPath + "\\" + fName);
FileContent mediaContent = new FileContent("multipart/related", filePath);
File file = driveService.files().create(fileMetadata, mediaContent)
.setFields("id, parents")
.execute();
and it seems to work fine but I can't tell if the upload is finished. I found the following on here that should tell me when it's finished:
FOUND ON STACK OVERFLOW
import com.google.api.client.googleapis.media.MediaHttpUploader;
import com.google.api.client.googleapis.media.MediaHttpUploaderProgressListener;
public class UploadProgressListener implements MediaHttpUploaderProgressListener {
public void upLoadProgress(MediaHttpUploader mediaHttpUploader) throws IOException {
if (mediaHttpUploader == null) return;
switch (mediaHttpUploader.getUploadState()) {
case INITIATION_STARTED:
break;
case INITIATION_COMPLETE:
break;
case MEDIA_IN_PROGRESS:
break;
case MEDIA_COMPLETE:
//System.out.println("Upload is complete!");
case NOT_STARTED:
break;
default:
break;
}
}
}
Which looks great but I can't figure out how to implement it or if it will even still work with the new Google API.
I tried:
TRIED BUT DIDN'T WORK
UploadProgressListener ProgressListener;
ProgressListener.uploadProgress(file);
I get an error. It wants a MediaHttpUploader.... HELP
UPDATE : I did some testing and found "in my case" (windows platform), I would assume all but..., the program will not go on until the current upload is complete. I was looking to make sure I didn't over tax the system I was running it on so that was all I needed. If you actually need to know that it finished the upload in this case I guess you could just do a System.out.println("Complete.");
If anyone actually gets the UploadProgressListener to work I would still love to know how. Just out of curiosity.