Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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();
}
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:
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);
Hi there!
If you need more help you can view your support options (expected response time for a 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!