Java Google Drive SDK SocketTimeoutException on File.insert.execute

六月ゝ 毕业季﹏ 提交于 2019-12-12 15:55:58

问题


I have been using the Google Drive SDK in both Java and Objective-c for months now and suddenly today (Jul 10, 2013) inserting new files using the java api (google-api-client-1.15.0-rc.jar & version 1.14) is failing to execute on FileInsert.execute(). Here is the static helper method I've been using (basically a copy from the DrEdit tutorials):

    public static File insertFile(Drive driveService, String title, String description,
            String parentId, String mimeType, java.io.File content) {
        System.out.println("<GDrive insertFile> start");
        File body = new File();
        body.setTitle(title);
        body.setDescription(description);
        body.setMimeType(mimeType);

        if (parentId != null && parentId.length() > 0) {
            body.setParents( Arrays.asList(new ParentReference().setId(parentId)) );
        }
        Insert fileInsert = null;
        System.out.println("<GDrive insertFile> before content attache");
        if (content != null && content.length() > 0) {
            FileContent mediaContent = new FileContent(mimeType, content);
            try { fileInsert = driveService.files().insert(body, mediaContent); }
            catch (IOException e) { e.printStackTrace(); }
        } else {
            try { fileInsert = driveService.files().insert(body); }
            catch (IOException e) { e.printStackTrace(); }
        }

        try {
            if (fileInsert != null) {
                System.out.println("<GDrive insertFile> before execute");
                File file = fileInsert.execute();
                System.out.println("<GDrive insertFile> file posted " + file.getId());
                return file;
            } else return null;
        } catch (IOException e) {
            System.out.println("An error occured: " + e);
            return null;
        }
    }

Obviously System.out was used to locate the issue, it hangs up on "before execute". I haven't been able to find any posts about Google server issues or changes in how the api is to be used. Here is the error message that is logged when the app fails any time after 20 - 180 seconds:

An error occured: java.net.SocketTimeoutException: Read timed out
Exception in thread "main" java.lang.NullPointerException

Thanks.

来源:https://stackoverflow.com/questions/17583630/java-google-drive-sdk-sockettimeoutexception-on-file-insert-execute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!