public class DropboxAPI.ChunkedUploader
extends java.lang.Object
DropboxAPI api = ...
File bigFile = new File("99mb.avi");
FileInputStream in = new FileInputStream(bigFile);
DropboxAPI.Entry uploadedFileMetadata;
try {
DropboxAPI.ChunkedUploader uploader = api.getChunkedUploader(in, bigFile.length());
int retryCounter = 0;
while(!uploader.isComplete()) {
try {
uploader.upload();
} catch (DropboxException e) {
if (retryCounter > MAX_RETRIES) break; // Give up after a while.
retryCounter++;
// Maybe wait a few seconds before retrying?
}
}
uploadedFileMetadata = uploader.finish("/Videos/99mb.avi", null);
} finally {
in.close();
}
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Aborts this chunked upload if it was already in progress.
|
DropboxAPI.Entry |
finish(java.lang.String path,
java.lang.String parentRev)
Completes a chunked upload, commiting the already uploaded file to Dropbox.
|
boolean |
getActive()
Whether or not this ChunkedUploader is active and has not yet been aborted.
|
long |
getOffset()
Returns the last-known byte offset that the server expects to receive.
|
boolean |
isComplete()
Whether or not this ChunkedUploader has completed its upload.
|
void |
upload()
Convenience wrapper around
upload(ProgressListener)
defaulting to a chunk size of 4 megabytes and no progress listener. |
void |
upload(ProgressListener listener)
Uploads multiple chunks of data to the server until the upload is complete or an
error occurs.
|
public long getOffset()
public boolean isComplete()
public boolean getActive()
isComplete().public void abort()
public void upload()
throws DropboxException,
java.io.IOException
upload(ProgressListener)
defaulting to a chunk size of 4 megabytes and no progress listener.DropboxException - If there was a transmission errorjava.io.IOException - If there was a problem reading from the given InputStream.DropboxPartialFileException - if the request was canceled before completion.public void upload(ProgressListener listener) throws DropboxException, java.io.IOException
listener - A ProgressListener (can be null) that will be notified of upload
progress. The progress notifications will be for the entire file.DropboxException - If there was a transmission errorjava.io.IOException - If there was a problem reading from the given InputStream.DropboxPartialFileException - if the request was canceled before completion.public DropboxAPI.Entry finish(java.lang.String path, java.lang.String parentRev) throws DropboxException
path - the full Dropbox path where to put the file, including
directories and filename.parentRev - the rev of the file at which the user started editing
it (obtained from a metadata call), or null if this is a new
upload. If null, or if it does not match the latest rev on the
server, a copy of the file will be created and you'll receive
the new metadata upon executing the request.DropboxException - if anything goes wrong.