We Want to Hear From You! What Do You Want to See on the Community? Tell us here!

Forum Discussion

RajdeepRoy's avatar
RajdeepRoy
New member | Level 2
5 years ago

com.dropbox.core.NetworkIOException: Error writing request body to server

I've created following script to upload all files from folder.

===============================================

import com.dropbox.core.DbxException;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.users.FullAccount;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.Metadata;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.File;

public class DriveQuickstart {
private static final String ACCESS_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static final String backupDir="WE0627";

public static void main(String args[]) throws DbxException {
// Create Dropbox client
DbxRequestConfig config = DbxRequestConfig.newBuilder("dropbox/java-tutorial").build();
DbxClientV2 client = new DbxClientV2(config, ACCESS_TOKEN);
FullAccount account = client.users().getCurrentAccount();
System.out.println(account.getName().getDisplayName());

try{
File dataFolder = new File("data");
if(dataFolder != null){
File[] listOfDataDirFiles = dataFolder.listFiles();
if(listOfDataDirFiles != null ){
for(File f: listOfDataDirFiles){
FileMetadata metadata = client.files().uploadBuilder("/TT Screenshots/"+backupDir+"/"+f.getName()).uploadAndFinish(new FileInputStream(f));
}
}
}
}catch(Exception e){
e.printStackTrace();
}
}
}

=================================================

script is working fine with smaller files(tested with 3 4 test.txt) but it uploads only 67 files from N numbers of files, which are 250MB on average in size.

 

it's showing following exception 

com.dropbox.core.NetworkIOException: Error writing request body to server
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:123)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:96)
at com.dropbox.core.v2.DbxUploadStyleBuilder.uploadAndFinish(DbxUploadStyleBuilder.java:92)
at DriveQuickstart.main(DriveQuickstart.java:56)
Caused by: com.dropbox.core.util.IOUtil$WriteException: Error writing request body to server
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:61)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:68)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:43)
at com.dropbox.core.http.HttpRequestor$Uploader.upload(HttpRequestor.java:103)
at com.dropbox.core.DbxUploader.uploadAndFinish(DbxUploader.java:118)
... 3 more
Caused by: java.io.IOException: Error writing request body to server
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.checkError(HttpURLConnection.java:3597)
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.write(HttpURLConnection.java:3580)
at com.dropbox.core.util.ProgressOutputStream.write(ProgressOutputStream.java:27)
at com.dropbox.core.util.IOUtil.copyStreamToStream(IOUtil.java:59)
... 7 more

 

Please advice on this. Thanks 

1 Reply

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    5 years ago

    The uploadBuilder method should only be used for uploading files smaller than 150 MB. For larger files, you need to use upload sessions. Please refer to the documentation for more information. You can find example code here.

About Discuss Dropbox Developer & API

Node avatar for Discuss Dropbox Developer & API
Make connections with other developers814 PostsLatest Activity: 15 hours ago
274 Following

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 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!