0
votes

How do I upload a file public and get link ? I am using Dropbox Java core api. Here.

  public static void Yukle(File file) throws DbxException, IOException {
    FileInputStream fileInputStream = new FileInputStream(file);
    InputStream inputStream = fileInputStream;
    try (InputStream in = new FileInputStream(file)) {
        UploadBuilder metadata = clientV2.files().uploadBuilder("/"+file.getName());
        metadata.withMode(WriteMode.OVERWRITE);
        metadata.withClientModified(new Date());
        metadata.withAutorename(false);
        metadata.uploadAndFinish(in);
        System.out.println(clientV2.files());
    }
}
1
[Cross-linking for reference: dropboxforum.com/hc/en-us/community/posts/… ] - Greg

1 Answers

0
votes

I use the following code to upload files to DropBox:

public DropboxAPI.Entry uploadFile(final String fullPath, final InputStream is, final long length, final boolean replaceFile) {
    final DropboxAPI.Entry[] rev = new DropboxAPI.Entry[1];
    rev[0] = null;
    Thread t = new Thread(new Runnable() {
        public void run() {
            try {
                if (replaceFile == true) {
                    try {
                        mDBApi.delete(fullPath);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    //! ReplaceFile is always true
                    rev[0] = mDBApi.putFile(fullPath, is, length, null, true, null);
                } else {
                    rev[0] = mDBApi.putFile(fullPath, is, length, null, null);
                }
            } catch (DropboxException e) {
                e.printStackTrace();
            }
        }
    });
    t.start();
    try {
        t.join();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    return rev[0];
}