0

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. 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

<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

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

1

1 Answer 1

0

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)

Ref :

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

1
  • hi @Senthil thank you for your response I am new in java can you please tell where should I need to change in my code for Uploading file, currently I give direct file path but now I am looking for upload file by selecting from the system instead of giving a full path of a file. thank you. Commented Dec 3, 2018 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.