@@ -159,7 +159,7 @@ private void handleFileUpload(final String uploadId, final String url, final Str
159
159
InputStream responseStream = null ;
160
160
161
161
try {
162
- conn = getMultipartHttpURLConnection (url , method , boundary );
162
+ conn = getMultipartHttpURLConnection (url , method , boundary , filesToUpload . size () );
163
163
164
164
setRequestHeaders (conn , requestHeaders );
165
165
@@ -233,18 +233,20 @@ private byte[] getTrailerBytes(final String boundary) throws UnsupportedEncoding
233
233
return builder .toString ().getBytes ("US-ASCII" );
234
234
}
235
235
236
- private
237
- HttpURLConnection
238
- getMultipartHttpURLConnection (final String url , final String method , final String boundary )
239
- throws IOException {
236
+ private HttpURLConnection getMultipartHttpURLConnection (final String url , final String method ,
237
+ final String boundary , int totalFiles ) throws IOException {
240
238
final HttpURLConnection conn = (HttpURLConnection ) new URL (url ).openConnection ();
241
239
242
240
conn .setDoInput (true );
243
241
conn .setDoOutput (true );
244
242
conn .setUseCaches (false );
245
243
conn .setChunkedStreamingMode (0 );
246
244
conn .setRequestMethod (method );
247
- conn .setRequestProperty ("Connection" , "close" );
245
+ if (totalFiles <= 1 ) {
246
+ conn .setRequestProperty ("Connection" , "close" );
247
+ } else {
248
+ conn .setRequestProperty ("Connection" , "Keep-Alive" );
249
+ }
248
250
conn .setRequestProperty ("ENCTYPE" , "multipart/form-data" );
249
251
conn .setRequestProperty ("Content-Type" , "multipart/form-data; boundary=" + boundary );
250
252
0 commit comments