Download Folder with API V2 [ Not file , i need to download folder/s]
See original GitHub issueI know how to download a File and get also the progress , but i don’t know how to do it for a Folder . For example on the DropBox website when you click to download a folder , it downloads it as a .zip . How this can be done ? I CAN’T FIND NO WHERE AN EXAMPLE OF THIS 😃 please some help .
So downloading a File with the API V2 is pretty easy like :
/**
* Download Dropbox File to Local Computer
*
* @param client
* Current connected client
* @param dropBoxFilePath
* The file path on the Dropbox cloud server -> [/foldername/something.txt]
* @param localFileAbsolutePath
* The absolute file path of the File on the Local File System
* @throws DbxException
* @throws DownloadErrorException
* @throws IOException
*/
public void downloadFile(DbxClientV2 client , String dropBoxFilePath , String localFileAbsolutePath) throws DownloadErrorException , DbxException , IOException {
//Create DbxDownloader
DbxDownloader<FileMetadata> dl = client.files().download(dropBoxFilePath);
//FileOutputStream
FileOutputStream fOut = new FileOutputStream(localFileAbsolutePath);
System.out.println("Downloading .... " + dropBoxFilePath);
//Add a progress Listener
dl.download(new ProgressOutputStream(fOut, dl.getResult().getSize(), (long completed , long totalSize) -> {
System.out.println( ( completed * 100 ) / totalSize + " %");
}));
}
where ProgressOutputStream
is the below :
import java.io.IOException;
import java.io.OutputStream;
/**
* Used to track progress of OutputStream User
*
* @author GOXR3PLUS
*
*/
public class ProgressOutputStream extends OutputStream {
private OutputStream underlying;
private Listener listener;
private int completed;
private long totalSize;
public ProgressOutputStream(OutputStream underlying, long totalSize, Listener listener) {
this.underlying = underlying;
this.listener = listener;
this.completed = 0;
this.totalSize = totalSize;
}
@Override
public void write(byte[] data , int off , int len) throws IOException {
this.underlying.write(data, off, len);
track(len);
}
@Override
public void write(byte[] data) throws IOException {
this.underlying.write(data);
track(data.length);
}
@Override
public void write(int c) {
try {
this.underlying.write(c);
track(1);
} catch (IOException e) {
e.printStackTrace();
}
}
private void track(int len) {
this.completed += len;
this.listener.progress(this.completed, this.totalSize);
}
/**
* The total File size
*
* @return the totalSize The total File size
*/
public long getTotalSize() {
return totalSize;
}
public interface Listener {
public void progress(long completed , long totalSize);
}
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
Download folder as ZIP in api v2?
Hi Tim, API v2 doesn't offer zip folder downloads, but I'll pass this along as a feature request. (Also, I'm not sure exactly...
Read more >REST API for Documents - Bulk Download Folders and Files
The REST API for Documents enables you to interact with folders and files stored ... Requests a bulk download of the specified globally...
Read more >Working with folders and files with REST
Perform basic create, read, update, and delete (CRUD) operations on folders and files with the SharePoint REST interface.
Read more >Download folder with Google Drive API
There is no single method that will allow you to download everything with in a folder. Your going to have to do a...
Read more >ARTIFACTORY: How can I download folders with their ...
We can use the Retrieve Folder or Repository Archive REST API, which allows us to download the content of a folder as an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The API now offers the ability to download folders as zips. In the Java SDK, you can use the
downloadZip
method:https://dropbox.github.io/dropbox-sdk-java/api-docs/v3.0.x/com/dropbox/core/v2/files/DbxUserFilesRequests.html#downloadZip-java.lang.String-
OMG CHILL 3 minutes past lol. Check the repository XR3Player i have inside the code you want everything from download to upload. Give me time to find it if you don’t.
On Thu, Nov 29, 2018, 17:50 rahuldn <notifications@github.com wrote: