@@ -31,28 +31,23 @@ Add the following to your project's AndroidManifest.xml file:
31
31
32
32
## How to start android upload service to upload files
33
33
public void updateSomething(final Context context) {
34
- //The full URL to your server side HTTP multipart upload script
35
- final String serverUrl = "http://www.yourcompany.com/your/upload/script";
36
-
37
- final ArrayList<FileToUpload> files = new ArrayList<FileToUpload>();
38
- files.add(new FileToUpload("/absolute/path/to/your/file",
39
- "http-form-parameter-name",
40
- "content-type")); //You can find many common content types defined as static constants in the ContentType class
41
-
42
- //This is optional. If you don't want to add any specific headers, you can just leave the list empty
43
- final ArrayList<NameValue> headers = new ArrayList<NameValue>();
44
- headers.add(new NameValue("additional-header-name", "additional-header-value"));
45
-
46
- final ArrayList<NameValue> parameters = new ArrayList<NameValue>();
47
- parameters.add(new NameValue("parameter-name", "parameter-value"));
34
+ final UploadRequest request = new UploadRequest(context, "http://www.yourcompany.com/your/upload/script");
35
+
36
+ request.addFileToUpload("/absolute/path/to/your/file",
37
+ "parameter-name",
38
+ "content-type")); //You can find many common content types defined as static constants in the ContentType class
39
+
40
+ //You can add your own custom headers
41
+ request.addHeader("your-custom-header", "your-custom-value");
42
+
43
+ request.addParameter("parameter-name", "parameter-value");
48
44
49
45
//If you want to add an array of strings, you can simply to the following:
50
- parameters.add(new NameValue("array-parameter-name", "value1"));
51
- parameters.add(new NameValue("array-parameter-name", "value2"));
52
- parameters.add(new NameValue("array-parameter-name", "valueN"));
53
-
54
- UploadNotificationConfig notificationConfig =
55
- new UploadNotificationConfig(
46
+ request.addParameter("array-parameter-name", "value1");
47
+ request.addParameter("array-parameter-name", "value2");
48
+ request.addParameter("array-parameter-name", "valueN");
49
+
50
+ request.setNotificationConfig(
56
51
android.R.drawable.ic_menu_upload, //Notification icon. You can use your own app's R.drawable.your_resource
57
52
"notification title", //You can use your string resource with: context.getString(R.string.your_string)
58
53
"upload in progress text",
@@ -63,10 +58,9 @@ Add the following to your project's AndroidManifest.xml file:
63
58
try {
64
59
//Utility method that creates the intent and starts the upload service in the background
65
60
//As soon as the service starts, you'll see upload status in Android Notification Center :)
66
- UploadService.startUpload(context, notificationConfig, serverUrl, files, headers, parameters);
67
-
61
+ UploadService.startUpload(request);
68
62
} catch (Exception exc) {
69
- //You will end up here only if you pass null parameters or an invalid server URL
63
+ //You will end up here only if you pass an incomplete UploadRequest
70
64
Log.e("AndroidUploadService", exc.getLocalizedMessage(), exc);
71
65
}
72
66
}
0 commit comments