@@ -43,6 +43,7 @@ public class UploadService extends IntentService {
43
43
protected static final String PARAM_NOTIFICATION_CONFIG = "notificationConfig" ;
44
44
protected static final String PARAM_ID = "id" ;
45
45
protected static final String PARAM_URL = "url" ;
46
+ protected static final String PARAM_METHOD = "method" ;
46
47
protected static final String PARAM_FILES = "files" ;
47
48
protected static final String PARAM_REQUEST_HEADERS = "requestHeaders" ;
48
49
protected static final String PARAM_REQUEST_PARAMETERS = "requestParameters" ;
@@ -86,6 +87,7 @@ public static void startUpload(final UploadRequest task)
86
87
intent .putExtra (PARAM_NOTIFICATION_CONFIG , task .getNotificationConfig ());
87
88
intent .putExtra (PARAM_ID , task .getUploadId ());
88
89
intent .putExtra (PARAM_URL , task .getServerUrl ());
90
+ intent .putExtra (PARAM_METHOD , task .getMethod ());
89
91
intent .putParcelableArrayListExtra (PARAM_FILES , task .getFilesToUpload ());
90
92
intent .putParcelableArrayListExtra (PARAM_REQUEST_HEADERS , task .getHeaders ());
91
93
intent .putParcelableArrayListExtra (PARAM_REQUEST_PARAMETERS , task .getParameters ());
@@ -116,6 +118,7 @@ protected void onHandleIntent(Intent intent) {
116
118
notificationConfig = intent .getParcelableExtra (PARAM_NOTIFICATION_CONFIG );
117
119
final String uploadId = intent .getStringExtra (PARAM_ID );
118
120
final String url = intent .getStringExtra (PARAM_URL );
121
+ final String method = intent .getStringExtra (PARAM_METHOD );
119
122
final ArrayList <FileToUpload > files = intent .getParcelableArrayListExtra (PARAM_FILES );
120
123
final ArrayList <NameValue > headers = intent .getParcelableArrayListExtra (PARAM_REQUEST_HEADERS );
121
124
final ArrayList <NameValue > parameters = intent .getParcelableArrayListExtra (PARAM_REQUEST_PARAMETERS );
@@ -124,7 +127,7 @@ protected void onHandleIntent(Intent intent) {
124
127
wakeLock .acquire ();
125
128
try {
126
129
createNotification ();
127
- handleFileUpload (uploadId , url , files , headers , parameters );
130
+ handleFileUpload (uploadId , url , method , files , headers , parameters );
128
131
} catch (Exception exception ) {
129
132
broadcastError (uploadId , exception );
130
133
} finally {
@@ -136,6 +139,7 @@ protected void onHandleIntent(Intent intent) {
136
139
137
140
private void handleFileUpload (final String uploadId ,
138
141
final String url ,
142
+ final String method ,
139
143
final ArrayList <FileToUpload > filesToUpload ,
140
144
final ArrayList <NameValue > requestHeaders ,
141
145
final ArrayList <NameValue > requestParameters )
@@ -148,7 +152,7 @@ private void handleFileUpload(final String uploadId,
148
152
OutputStream requestStream = null ;
149
153
150
154
try {
151
- conn = getMultipartHttpURLConnection (url , boundary );
155
+ conn = getMultipartHttpURLConnection (url , method , boundary );
152
156
153
157
setRequestHeaders (conn , requestHeaders );
154
158
@@ -205,14 +209,15 @@ private byte[] getTrailerBytes(final String boundary)
205
209
}
206
210
207
211
private HttpURLConnection getMultipartHttpURLConnection (final String url ,
212
+ final String method ,
208
213
final String boundary )
209
214
throws IOException {
210
215
final HttpURLConnection conn = (HttpURLConnection ) new URL (url ).openConnection ();
211
216
212
217
conn .setDoInput (true );
213
218
conn .setDoOutput (true );
214
219
conn .setUseCaches (false );
215
- conn .setRequestMethod ("POST" );
220
+ conn .setRequestMethod (method );
216
221
conn .setRequestProperty ("Connection" , "Keep-Alive" );
217
222
conn .setRequestProperty ("ENCTYPE" , "multipart/form-data" );
218
223
conn .setRequestProperty ("Content-Type" , "multipart/form-data; boundary=" + boundary );
0 commit comments