We're making changes to the Community, so you may have received some notifications - thanks for your patience and welcome back. Learn more here.

Forum Discussion

Максим Б.'s avatar
Максим Б.
New member | Level 1
9 years ago

Help upload file 20-100mb

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();
}
  • Максим Б.'s avatar
    Максим Б.
    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);

About Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,875 PostsLatest Activity: 27 minutes ago
323 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!