Forum Discussion

Максим Б.'s avatar
Максим Б.
New member | Level 1
10 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();
}

2 Replies

Replies have been turned off for this discussion
  • Максим Б.'s avatar
    Максим Б.
    New member | Level 1
    10 years ago

    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

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!