2016-09-06 27 views
0

Wie lade ich eine Datei öffentlich und bekomme einen Link? Ich benutze Dropbox Java Core API. Here.Dropbox Java API Datei hochladen

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()); 
    } 
} 
+0

[Vernetzungs Referenz: https://www.dropboxforum.com/hc/en-us/community/posts/210944726-Dropbox-Java-API-Upload-Öffentlicher Ordner-] – Greg

Antwort

0

Ich verwende den folgenden Code-Dateien in Dropbox hochladen:

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