cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
We are making some updates so the Community might be down for a few hours on Monday the 11th of November. Apologies for the inconvenience and thank you for your patience. You can find out more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help upload file 20-100mb

Help upload file 20-100mb

Максим Б.
New member | Level 1

Hello. I can not upload files larger than 10MB . Can someone help me ? I'm a beginner in Java. Here is my code :

DbxClient client = connect();
BufferedInputStream file = new BufferedInputStream(new ByteArrayInputStream(body));

try {
if (body.length<8381002) {
DbxEntry.File uploadedFile = client.uploadFile("/" + name,
DbxWriteMode.add(), body.length, file);
} else {
//* How ???
}
return true;
} catch (Exception e){
e.printStackTrace();
return false;
}finally {
file.close();
}
2 Replies 2

Greg-DB
Dropbox Staff

For larger files, you should use chunked uploading. It looks like you're using the Java SDK, so you can use the startUploadFile method, which will decide which kind of uploading to use for you:

https://dropbox.github.io/dropbox-sdk-java/api-docs/v1.8.x/com/dropbox/core/DbxClient.html#startUplo...

Максим Б.
New member | Level 1

i find it and it work 

Channel inputChannel = Channels.newChannel(file);
InputStream inputStream = null;
inputStream = Channels
.newInputStream((ReadableByteChannel) inputChannel);
ByteBuffer buffer = ByteBuffer.allocate(3276800); //chunk size
int bytesRead = ((ReadableByteChannel) inputChannel).read(buffer);
long uploadOffset = bytesRead, offset;
String uploadId = null;
while (bytesRead != -1) {
buffer.flip();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
if (uploadId == null) {
uploadId = client.chunkedUploadFirst(data);
} else {
offset = client.chunkedUploadAppend(uploadId, uploadOffset,
data);
while (offset != -1L) {
uploadOffset = offset;
offset = client.chunkedUploadAppend(uploadId,
uploadOffset, data);
}
}
buffer.clear();
bytesRead = ((ReadableByteChannel) inputChannel).read(buffer);
uploadOffset += bytesRead;
}

client.chunkedUploadFinish("/"+name, DbxWriteMode.add(), uploadId);
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Максим Б. New member | Level 1
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?