cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Discuss Dropbox Developer & API

cancel
Showing results forĀ 
ShowĀ Ā onlyĀ  | Search instead forĀ 
Did you mean:Ā 

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

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

FugetronDolphin
Helpful | Level 6
Go to solution

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

2 Accepted Solutions

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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

View solution in original post

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/53532632/java-web-project-integration-with-dropbox-api ]

It sounds like your question is about getting the input stream for a local file. This isn't directly related to Dropbox itself, so I'm afraid I can't be of much help with this. You may be better suited by referring to general Java IO documentation or guides for interacting with the local file system.

By the way, I redacted it from your post, but for the sake of security, you should disable that access token that you posted. You can do so by revoking access to the app entirely, if the access token is for your account, here:

https://www.dropbox.com/account/connected_apps

Or, you can disable just this access token using the API:

https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke

You can do so in the Java SDK itself:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/auth/DbxUserAuthReque...

Or in the API v2 Explorer if you want:

https://dropbox.github.io/dropbox-api-v2-explorer/#auth_token/revoke

View solution in original post

4 Replies 4

Greg-DB
Dropbox Staff
Go to solution

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
Helpful | Level 6
Go to solution

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

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/53532632/java-web-project-integration-with-dropbox-api ]

It sounds like your question is about getting the input stream for a local file. This isn't directly related to Dropbox itself, so I'm afraid I can't be of much help with this. You may be better suited by referring to general Java IO documentation or guides for interacting with the local file system.

By the way, I redacted it from your post, but for the sake of security, you should disable that access token that you posted. You can do so by revoking access to the app entirely, if the access token is for your account, here:

https://www.dropbox.com/account/connected_apps

Or, you can disable just this access token using the API:

https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke

You can do so in the Java SDK itself:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/auth/DbxUserAuthReque...

Or in the API v2 Explorer if you want:

https://dropbox.github.io/dropbox-api-v2-explorer/#auth_token/revoke

jboyce
New member | Level 2
Go to solution

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!?

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    jboyce New member | Level 2
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    FugetronDolphin Helpful | Level 6
What do Dropbox user levels mean?