简体   繁体   English

Java Web项目与Dropbox API的集成

[英]Java Web project Integration with Dropbox API

I am facing trouble in integrating my project with dropbox I use Dropbox For upload file here I am able to upload the file by giving complete Path Of file. 我在将项目与Dropbox集成时遇到麻烦,我使用Dropbox在此处上传文件时,我可以通过提供完整的文件路径来上传文件。 but I want to upload file by selecting or Brows from the system and upload to my dropbox Here my code is Like Static For Uploading the file by giving complete file path for upload now I want to upload file by selecting from disck here I use this code for selecting the file but i dont know how to pass this selected file as input for FileInputStream in my DbxUpload class 但是我想通过选择或从系统中浏览来上传文件并上传到我的保管箱这里,我的代码就像静态的那样,通过提供完整的文件路径来上传文件,现在我想通过从磁盘中选择来上传文件,我在这里使用此代码用于选择文件,但我不知道如何将此选定文件作为DbxUpload类中FileInputStream的输入

<body> <a>Select to Upload</a><br><br> Select file: <br /> <form action="DbxUpload" method="Post" enctype="multipart/form-data"> <input type="file" name="file" size="70" /> <br /> <input type="submit" value="Upload File" />

Here my DbxUpload Class code that iam using 这是我使用的我的DbxUpload类代码

import com.dropbox.core.*;
import java.io.*;

public class DbxUpload
{  
 private static final String ACCESS_TOKEN = "XXXXXXXXXXXXXXX";

    public static void main(String args[]) throws DbxException, IOException {
        // Create Dropbox client
        DbxRequestConfig config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
        DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);

        // Get current account info
        FullAccount account = client.users().getCurrentAccount();
        System.out.println(account.getName().getDisplayName());

        // Get files and folder metadata from Dropbox root directory
        ListFolderResult result = client.files().listFolder("");
        while (true) {
            for (Metadata metadata : result.getEntries()) {
                System.out.println(metadata.getPathLower());
            }

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

            result = client.files().listFolderContinue(result.getCursor());
        }

        // Upload "test.txt" to Dropbox
        try (InputStream in = new FileInputStream("D:/RUNNING.txt")) {
            FileMetadata metadata = client.files().uploadBuilder("/RUNNING.txt")
                .uploadAndFinish(in);
        }
    }
}

Please Help me Thanks in Advance 请帮我提前谢谢

Using web File browser, this is the entry point https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/web-file-browser/src/main/java/com/dropbox/core/examples/web_file_browser/Main.java where the user can start browse and upload a file to drop box api using Jetty application (uses Jetty server and servlet in the program to support file upload to drop box) 使用网络文件浏览器,这是入口点https://github.com/dropbox/dropbox-sdk-java/blob/master/examples/web-file-browser/src/main/java/com/dropbox/core/ examples / web_file_browser / Main.java ,用户可以在其中开始使用Jetty应用程序浏览文件并将文件上传到下拉框api(在程序中使用Jetty服务器和servlet支持文件上传到下拉框)

Ref : 参考:

https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/web-file-browser/src/main/java/com/dropbox/core/examples/web_file_browser https://github.com/dropbox/dropbox-sdk-java/tree/master/examples/web-file-browser/src/main/java/com/dropbox/core/examples/web_file_browser

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM