Google Drive API Java-我的大型分段上传完成了吗?

问题描述 投票:1回答:1

我正在尝试使用以下方法从本地计算机自动将大文件上传到Google驱动器:

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();

并且似乎工作正常,但我无法确定上传是否完成。我在这里发现以下内容,应该告诉我何时完成:

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;
        }
    }
}

哪个看起来很棒,但我不知道如何实现它,或者它是否仍可以在新的Google API中使用。

我尝试过:

UploadProgressListener ProgressListener;

ProgressListener.uploadProgress(file);

我收到一个错误。它需要一个MediaHttpUploader。...帮助

java google-drive-api
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.