首页 > 解决方案 > 在 DropBoxAPI 本身中创建和编辑临时文件,然后保存/上传它

问题描述

我有一段代码在其中检查保管箱文件夹中的某个文件(.xlsx):

 ListFolderResult result = client.files().listFolder("some path");
        while (true) {
            for (Metadata metadata : result.getEntries()) {
                if(metadata.getName().equalsIgnoreCase(name))
                {
                    System.out.println("Already exists file with name"+name);
                    return true;              //file exists.
                }
             }

            if (!result.getHasMore()) {
                break;
            }

            result = client.files().listFolderContinue(result.getCursor());
        }
        return false;   //file doesn't exists

这只是搜索该文件并根据它返回一个布尔值。

现在,我想要的是在保管箱本身中创建一个同名文件,而不是在我的本地系统中创建它然后上传它。我目前拥有的是:

Boolean ifExists = checkInDrop(client,userName);   //client is dropbox config client and checkInDrop() is mentioned above.
        if(ifExists==false) 
        {
            try (InputStream in = new FileInputStream(userName+".xlsx")) 
            {
                FileMetadata metadata = client.files().uploadBuilder("the same path mentioned above"+userName+".xlsx")
                    .uploadAndFinish(in);
            }
        }

如果可能的话,你们可以建议吗?如果是,那怎么办?

谢谢。

标签: javadropboxdropbox-api

解决方案


推荐阅读