@@ -193,23 +193,48 @@ public void put(String key, String value) {
193
193
* @throws java.io.FileNotFoundException throws if wrong File argument was passed
194
194
*/
195
195
public void put (String key , File file ) throws FileNotFoundException {
196
- put (key , file , null );
196
+ put (key , file , null , null );
197
197
}
198
198
199
199
/**
200
- * Adds a file to the request.
200
+ * Adds a file to the request with custom provided file name
201
+ *
202
+ * @param key the key name for the new param.
203
+ * @param file the file to add.
204
+ * @param customFileName file name to use instead of real file name
205
+ * @throws java.io.FileNotFoundException throws if wrong File argument was passed
206
+ */
207
+ public void put (String key , String customFileName , File file ) throws FileNotFoundException {
208
+ put (key , file , null , customFileName );
209
+ }
210
+
211
+ /**
212
+ * Adds a file to the request with custom provided file content-type
201
213
*
202
214
* @param key the key name for the new param.
203
215
* @param file the file to add.
204
216
* @param contentType the content type of the file, eg. application/json
205
217
* @throws java.io.FileNotFoundException throws if wrong File argument was passed
206
218
*/
207
219
public void put (String key , File file , String contentType ) throws FileNotFoundException {
220
+ put (key , file , contentType , null );
221
+ }
222
+
223
+ /**
224
+ * Adds a file to the request with both custom provided file content-type and file name
225
+ *
226
+ * @param key the key name for the new param.
227
+ * @param file the file to add.
228
+ * @param contentType the content type of the file, eg. application/json
229
+ * @param customFileName file name to use instead of real file name
230
+ * @throws java.io.FileNotFoundException throws if wrong File argument was passed
231
+ */
232
+ public void put (String key , File file , String contentType , String customFileName ) throws FileNotFoundException {
208
233
if (file == null || !file .exists ()) {
209
234
throw new FileNotFoundException ();
210
235
}
211
236
if (key != null ) {
212
- fileParams .put (key , new FileWrapper (file , contentType ));
237
+ fileParams .put (key , new FileWrapper (file , contentType , customFileName ));
213
238
}
214
239
}
215
240
@@ -495,7 +520,7 @@ private HttpEntity createMultipartEntity(ResponseHandlerInterface progressHandle
495
520
// Add file params
496
521
for (ConcurrentHashMap .Entry <String , FileWrapper > entry : fileParams .entrySet ()) {
497
522
FileWrapper fileWrapper = entry .getValue ();
498
- entity .addPart (entry .getKey (), fileWrapper .file , fileWrapper .contentType );
523
+ entity .addPart (entry .getKey (), fileWrapper .file , fileWrapper .contentType , fileWrapper . customFileName );
499
524
}
500
525
501
526
return entity ;
@@ -561,10 +586,12 @@ protected String getParamString() {
561
586
public static class FileWrapper {
562
587
public final File file ;
563
588
public final String contentType ;
589
+ public final String customFileName ;
564
590
565
- public FileWrapper (File file , String contentType ) {
591
+ public FileWrapper (File file , String contentType , String customFileName ) {
566
592
this .file = file ;
567
593
this .contentType = contentType ;
594
+ this .customFileName = customFileName ;
568
595
}
569
596
}
570
597
0 commit comments