Google 驱动文件上传正在转换为文档

Google drive file uploads getting converted to doc

我正在使用 google 驱动器 V3 REST api 从 POST 请求上传一个多部分文件 & 下面是 java 代码

                String accessToken = "xyz";
                    Credential credential = new GoogleCredential().setAccessToken(accessToken);
                    Drive service = new Drive.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                            .setApplicationName("xyz")
                            .build();
                File fileMeta = new File();
                fileMeta.setName(fileName);
                fileMeta.setMimeType("application/vnd.google-apps.file");
                if (!parentFolderId.isEmpty()) {
                    fileMeta.setParents(Collections.singletonList(parentFolderId));
                }
                //Code to upload file in GDrive
                java.io.File tmpFile = java.io.File.createTempFile("uploadFile", ".tmp");

                //Writing the file content to the new file
                InputStream in = multipartFile.getInputStream();
                FileOutputStream fos = new FileOutputStream(tmpFile);

                IOUtils.copy(in, fos);

                in.close();
                fos.close();

                tmpFile.deleteOnExit();
                FileContent mediaContent = new FileContent(null, tmpFile);
                File file = service.files().create(fileMeta, mediaContent)
                        .setFields("id")
                        .execute();

上传工作正常,但所有上传都自动转换为我不想要的文档。我从问题Google Drive: Automatically convert files on upload?中看到,插入时需要设置convert=true。但此选项在 V3 中不可用。

谁能告诉我如何在上传期间禁用此自动转换?

auto-conversion 的原因是因为在文件对象中设置了 mime 类型,因此每个上传的文件都被转换为 google 文档

fileMeta.setMimeType("application/vnd.google-apps.file");

上传时未在文件对象中设置 mimeType 后,此问题得到解决