question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Download Folder with API V2 [ Not file , i need to download folder/s]

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
greg-dbcommented, Jan 26, 2018

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-

2reactions
goxr3pluscommented, Nov 29, 2018

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:

@goxr3plus https://github.com/goxr3plus I couldn’t find it anywhere!! API v2…!! I read your comment… so could you share source code with me!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/dropbox/dropbox-sdk-java/issues/170#issuecomment-442883773, or mute the thread https://github.com/notifications/unsubscribe-auth/ATbiwHUCWwsThh60O7OeE1UOCekBZTyiks5u0AJbgaJpZM4QpO1u .

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found