Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Google Drive API V3下载返回416错误_Java_Google Api_Google Drive Api - Fatal编程技术网

Java Google Drive API V3下载返回416错误

Java Google Drive API V3下载返回416错误,java,google-api,google-drive-api,Java,Google Api,Google Drive Api,我在Google drive中有一个bin子文件夹,其中包含1500-1600个bin文件,存储空间大约为1GB。 我的程序停止下载544个文件,我不知道为什么。 以下是我在Google API控制台中的限制: 配额名称限制 每天查询100000000次 每100秒每用户查询1000次 每100秒查询10000次 下面是编译bin文件列表的方法 public static final List<File> getbinfolderlist(Drive service, Strin

我在Google drive中有一个bin子文件夹,其中包含1500-1600个bin文件,存储空间大约为1GB。 我的程序停止下载544个文件,我不知道为什么。 以下是我在Google API控制台中的限制:

  • 配额名称限制
  • 每天查询100000000次
  • 每100秒每用户查询1000次
  • 每100秒查询10000次
下面是编译bin文件列表的方法

public static final List<File> getbinfolderlist(Drive service, String bin_folder_id) throws IOException {
        try {
            List<File> list = new ArrayList<File>();
            String pageToken = null;
            do {
                FileList result = service.files().list()
                    .setQ("'" + bin_folder_id + "' in parents")
                    .setPageToken(pageToken)
                    .execute();
                    for (File file : result.getFiles()) {
                        list.add(file);
                    }
                    pageToken = result.getNextPageToken();
                } while (pageToken != null);
                return list;
        } catch (Exception e) {
            return null;
        }
    }
我收到的错误消息是:

com.google.api.client.http.HttpResponseException: 416 Requested range not satisfiable
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "requestedRangeNotSatisfiable",
    "message": "Request range not satisfiable"
   }
  ],
  "code": 416,
  "message": "Request range not satisfiable"
 }
}

        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1070)
        at com.google.api.client.googleapis.media.MediaHttpDownloader.executeCurrentRequest(MediaHttpDownloader.java:245)
        at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:199)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAndDownloadTo(AbstractGoogleClientRequest.java:562)
        at com.google.api.services.drive.Drive$Files$Get.executeMediaAndDownloadTo(Drive.java:3256)
        at DriveQuickstart.downloadBinFiles(DriveQuickstart.java:223)
        at DriveQuickstart.main(DriveQuickstart.java:127)

编辑:如果这是相关的,bin文件的大小范围从<0 KB到略低于14000 KB。文件夹大小为843 MB

异常的错误代码和消息是什么?这可能比仅仅打印“错误”更有用。@Cheticamp编辑了帖子以包含错误消息,该错误消息是HTTP 416错误代码(HttpResponseException),与驱动器没有特定关系。我会查看544号文件,看看是否有任何问题。您可以搜索代码,查看其他人遇到了什么麻烦以及他们找到了什么解决方案。这看起来不像是限制问题。@Cheticamp某些文件是零字节文件。如何保持程序运行,以便在遇到零字节文件时跳过它并继续下一个文件?您可以尝试在循环中移动try..catch块。我发现很难相信驱动器不能处理零长度的文件。我会先检查一下,也许在尝试下载之前会发现如何检查长度。
public static void downloadBinFiles(Drive service, List<File> bin_files, String dst_dir) {
        try {
            int i = 0;
            for (File file : files) {
                String fileId = file.getId();
                String fileName = file.getName();
                //need to check if folder exists. If not, create folder.
                System.out.println("File downloading is: " + fileName);
                OutputStream outputstream = new FileOutputStream(dst_dir + fileName);
                    service.files().get(fileId)
                        .executeMediaAndDownloadTo(outputstream);
                    outputstream.flush();
                    outputstream.close();
                i++;
                System.out.println(i + " files downloaded.");
                }
        } catch (Exception e) {
            Console console = System.console();
            console.writer().println("Error.");
        }
    }
downloadBinFiles(service, bin_files, bin_path );
com.google.api.client.http.HttpResponseException: 416 Requested range not satisfiable
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "requestedRangeNotSatisfiable",
    "message": "Request range not satisfiable"
   }
  ],
  "code": 416,
  "message": "Request range not satisfiable"
 }
}

        at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1070)
        at com.google.api.client.googleapis.media.MediaHttpDownloader.executeCurrentRequest(MediaHttpDownloader.java:245)
        at com.google.api.client.googleapis.media.MediaHttpDownloader.download(MediaHttpDownloader.java:199)
        at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMediaAndDownloadTo(AbstractGoogleClientRequest.java:562)
        at com.google.api.services.drive.Drive$Files$Get.executeMediaAndDownloadTo(Drive.java:3256)
        at DriveQuickstart.downloadBinFiles(DriveQuickstart.java:223)
        at DriveQuickstart.main(DriveQuickstart.java:127)