0

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

1 Answer 1

0

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];
}

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.