将文件上传到Google云端硬盘中的特定文件夹

Kertix:

我有两种方法,一种用于创建文件并将其上传到Google驱动器的根文件夹,第二种仅用于创建Google驱动器的文件夹。

是否有可能以某种方式将这两者连接起来并将文件上传到该新创建的文件夹?

我已阅读过Google文档,但无法弄清楚该文件可以转到哪个文件夹的位置

要创建文件:

    private Task<Void> createFileIntentSender(DriveContents driveContents, File file) throws FileNotFoundException {
        Log.i(TAG, "New contents created.");

        // Get an output stream for the contents.
        OutputStream outputStream = driveContents.getOutputStream();

        byte[] bytesArray = new byte[(int) file.length()];

        FileInputStream fis = null;
        try {
            fis = new FileInputStream(file);
            fis.read(bytesArray); //read file into bytes[]
            fis.close();
            outputStream.write(bytesArray);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                .setTitle(windowName.getText().toString())
                .setMimeType("application/vnd.ms-excel")
                .setStarred(true)
                .build();

        // Set up options to configure and display the create file activity.
        CreateFileActivityOptions createFileActivityOptions =
                new CreateFileActivityOptions.Builder()
                        .setInitialMetadata(changeSet)
                        .setInitialDriveContents(driveContents)
                        .build();

        return mDriveClient
                .newCreateFileActivityIntentSender(createFileActivityOptions)
                .continueWith(
                        new Continuation<IntentSender, Void>() {
                            @Override
                            public Void then(@NonNull Task<IntentSender> task) throws Exception {
                                startIntentSenderForResult(task.getResult(), REQUEST_CODE_CREATOR, null, 0, 0, 0);
                                return null;
                            }
                        });
    }

创建文件夹:

    private void createFolder() {
        mDriveResourceClient.getRootFolder()
                .continueWithTask(task -> {
                    DriveFolder parentFolder = task.getResult();
                    MetadataChangeSet changeSet = new MetadataChangeSet.Builder()
                            .setTitle("Folder1")
                            .setMimeType(DriveFolder.MIME_TYPE)
                            .setStarred(true)
                            .build();
                    return mDriveResourceClient.createFolder(parentFolder, changeSet);
                })
                .addOnFailureListener(this, e -> {
                    Log.e(TAG, "Unable to create file", e);
                    finish();
                });
    }
am

无需先将文件上传到root文件夹。您可以将文件直接上传到所需的文件夹。

首先,您需要创建要将文件上传的文件夹该方法返回一个文件资源filesfolders基本相同的驱动器,主要不同的是folders仅包含元数据,并具有MIME类型application/vnd.google-apps.folder)。

其次,您必须直接将文件上传到创建的文件夹中为此,在进行调用时,必须在文件folder IDparents属性中指定(可以从上一步的响应中获取)(选中此选项可查看可以在文件中指定的所有属性)。

希望对您有帮助。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Python:如何使用folderId将文件上传到Google云端硬盘中的特定文件夹

无法将文件上传到Google云端硬盘上的特定文件夹

无法将文件上传到Google云端硬盘中的文件夹

使用http上传到Google云端硬盘文件夹

将文件上传到Google云端硬盘?

当我尝试将文件上传到Google云端硬盘文件夹时,不断收到“服务器被拒绝”

无法使用Google App脚本上传到Google云端硬盘上的子文件夹

Google pydrive将文件上传到特定文件夹

如何将持续更新的文件夹上传到Google云端硬盘?

使用gapi将文件上传到Google云端硬盘

使用php curl将文件上传到Google云端硬盘

在后台将文件上传到Google云端硬盘

使用Dropzone将文件上传到Google云端硬盘

将文件从网络上传到Google云端硬盘

将文件从Blobstore上传到Google云端硬盘

使用意图将文件上传到Google云端硬盘

如何使用REST API将新修订版本上传到Google云端硬盘中的特定文件?

将文件夹从Google Colab移至Google云端硬盘

将内存中的文件下载并上传到Google云端硬盘

如何使用Apps脚本将云端硬盘中的现有文件上传到云端硬盘

将文件移动到Google云端硬盘中的其他文件夹

Django Python将文件上传到特定文件夹

使用Laravel将文件上传到特定文件夹

Owncloud将文件上传到特定文件夹-curl

将文件上传到特定文件夹 php

无法使用文件上传将图像上传到node.js中的特定文件夹

如何仅通过“备份和同步”同步Google云端硬盘中的特定文件夹?

Google云端硬盘API将文件上传到Java团队硬盘

Google 表单根据提交的值将文件上传到特定的新文件夹