You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

FugetronDolphin's avatar
FugetronDolphin
Helpful | Level 6
7 years ago

how to create Selective file Uploading feature in web application with Dropbox API

Hi,

I am creating a web application project and use Dropbox API for storing my Users file, where I want a user to upload their file after login in there account in a website (not a dropbox) and brows and upload file from the system and after submitted by the user this file is stored in a company Dropbox account with an automatically created folder of username 

I stuck here from last 4 day and already read the various document but I didn't get any help related to my specific requirements.

Please help if anyone have the solution 

Thank you in Advanced

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Dropbox does offer an API you can use for uploading and listing files, among other operations. You can find everything you need to get started with the Dropbox API, including documentation, tutorials, and SDKs here:

    https://www.dropbox.com/developers

    I recommend using one of the official SDKs, if possible, and following the respective tutorial to get started:

    https://www.dropbox.com/developers/documentation

    I also recommend reading the OAuth guide to understand how the authorization process works:

    https://www.dropbox.com/developers/reference/oauth-guide

    • FugetronDolphin's avatar
      FugetronDolphin
      Helpful | Level 6

      Hi Greg,

      Thank you for giving suggestion But I am not getting solution for my issue .

      I want pass My file to DbxUpload class After selecting from system. just same as 

      Drag photos/files here
       

      Not by giving path in class. 

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

      here i am stuck in how can i pass file  in InputStream by clicking on choose file button and select from disc not by directly give the file path

      i using this code. 

       

      1>>  Click on Upload Button.

      2>> Choose file from device.

      3>> Pass file to DbxUpload.java class as input from MyUpload.jsp page

       4>>Upload that file in Dropbox.

      Here I am Attaching my code that I use for uploading the file 

      <!DOCTYPE html>
      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
      <title>UploadFile</title>
      </head>
      <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" />
      </form>
      </body>
      </html>
      import com.dropbox.core.DbxException;
      import com.dropbox.core.DbxRequestConfig;
      import com.dropbox.core.v2.DbxClientV2;
      import com.dropbox.core.v2.files.FileMetadata;
      import com.dropbox.core.v2.files.ListFolderResult;
      import com.dropbox.core.v2.files.Metadata;
      import com.dropbox.core.v2.users.FullAccount;
      
      import java.io.FileInputStream;
      import java.io.InputStream;
      import java.io.IOException;
      
      public class DbxUpload {
          private static final String ACCESS_TOKEN = "<REDACTED>";
      
          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 suggest what modification I need to do for solving my issue

       

      Thank you in Advance

      Regards,

      Roshan

  • jboyce's avatar
    jboyce
    New member | Level 2

    I'm having the same issue. Did you ever get this solved? And if so, do you have a site I can reference for your example and maybe reach out to you on!?