@@ -20,6 +20,7 @@ class FileToUpload implements Parcelable {
20
20
private static final String NEW_LINE = "\r \n " ;
21
21
22
22
private final File file ;
23
+ private final String fileName ;
23
24
private final String paramName ;
24
25
private final String contentType ;
25
26
@@ -32,10 +33,16 @@ class FileToUpload implements Parcelable {
32
33
*/
33
34
public FileToUpload (final String path ,
34
35
final String parameterName ,
36
+ final String fileName ,
35
37
final String contentType ) {
36
38
this .file = new File (path );
37
39
this .paramName = parameterName ;
38
40
this .contentType = contentType ;
41
+ if (fileName == null || "" .equals (fileName )) {
42
+ this .fileName = this .file .getName ();
43
+ } else {
44
+ this .fileName = fileName ;
45
+ }
39
46
}
40
47
41
48
public final InputStream getStream () throws FileNotFoundException {
@@ -44,7 +51,7 @@ public final InputStream getStream() throws FileNotFoundException {
44
51
45
52
public byte [] getMultipartHeader () throws UnsupportedEncodingException {
46
53
String header = "Content-Disposition: form-data; name=\" "
47
- + paramName + "\" ; filename=\" " + file . getName () + "\" "
54
+ + paramName + "\" ; filename=\" " + fileName + "\" "
48
55
+ NEW_LINE + "Content-Type: " + contentType + NEW_LINE + NEW_LINE ;
49
56
return header .getBytes ("UTF-8" );
50
57
}
@@ -78,11 +85,13 @@ public void writeToParcel(Parcel parcel, int arg1) {
78
85
parcel .writeString (file .getAbsolutePath ());
79
86
parcel .writeString (paramName );
80
87
parcel .writeString (contentType );
88
+ parcel .writeString (fileName );
81
89
}
82
90
83
91
private FileToUpload (Parcel in ) {
84
92
file = new File (in .readString ());
85
93
paramName = in .readString ();
86
94
contentType = in .readString ();
95
+ fileName = in .readString ();
87
96
}
88
97
}
0 commit comments