public class MultipartUploadRequest extends HttpUploadRequest
Constructor and Description |
---|
MultipartUploadRequest(Context context,
String serverUrl)
Creates a new multipart upload request and automatically generates an upload id, that will
be returned when you call
HttpUploadRequest.startUpload() . |
MultipartUploadRequest(Context context,
String uploadId,
String serverUrl)
Creates a new multipart upload request.
|
Modifier and Type | Method and Description |
---|---|
MultipartUploadRequest |
addArrayParameter(String paramName,
List<String> list)
Adds a parameter with multiple values to this upload request.
|
MultipartUploadRequest |
addArrayParameter(String paramName,
String... array)
Adds a parameter with multiple values to this upload request.
|
MultipartUploadRequest |
addFileToUpload(String path,
String parameterName)
Adds a file to this upload request, without setting file name and content type.
|
MultipartUploadRequest |
addFileToUpload(String path,
String parameterName,
String fileName)
Adds a file to this upload request, without setting the content type, which will be
automatically detected from the file extension.
|
MultipartUploadRequest |
addFileToUpload(String path,
String parameterName,
String fileName,
String contentType)
Adds a file to this upload request.
|
MultipartUploadRequest |
addHeader(String headerName,
String headerValue)
Adds a header to this upload request.
|
MultipartUploadRequest |
addParameter(String paramName,
String paramValue)
Adds a parameter to this upload request.
|
MultipartUploadRequest |
setAutoDeleteFilesAfterSuccessfulUpload(boolean autoDeleteFiles)
Sets the automatic file deletion after successful upload.
|
MultipartUploadRequest |
setBasicAuth(String username,
String password)
Sets the HTTP Basic Authentication header.
|
MultipartUploadRequest |
setCustomUserAgent(String customUserAgent)
Sets the custom user agent to use for this upload request.
|
MultipartUploadRequest |
setMaxRetries(int maxRetries)
Sets the maximum number of retries that the library will do if an error occurs,
before returning an error.
|
MultipartUploadRequest |
setMethod(String method)
Sets the HTTP method to use.
|
MultipartUploadRequest |
setNotificationConfig(UploadNotificationConfig config)
Sets custom notification configuration.
|
MultipartUploadRequest |
setUsesFixedLengthStreamingMode(boolean fixedLength)
Sets if this upload request is using fixed length streaming mode.
|
MultipartUploadRequest |
setUtf8Charset()
Sets the charset for this multipart request to UTF-8.
|
startUpload
public MultipartUploadRequest(Context context, String uploadId, String serverUrl)
context
- application contextuploadId
- unique ID to assign to this upload request.UploadServiceBroadcastReceiver
,
you know to which upload they refer to.serverUrl
- URL of the server side script that will handle the multipart form upload.
E.g.: http://www.yourcompany.com/your/scriptpublic MultipartUploadRequest(Context context, String serverUrl)
HttpUploadRequest.startUpload()
.context
- application contextserverUrl
- URL of the server side script that will handle the multipart form upload.
E.g.: http://www.yourcompany.com/your/scriptpublic MultipartUploadRequest addFileToUpload(String path, String parameterName, String fileName, String contentType) throws FileNotFoundException, IllegalArgumentException
path
- Absolute path to the file that you want to uploadparameterName
- Name of the form parameter that will contain file's datafileName
- File name seen by the server side script. If null, the original file name
will be usedcontentType
- Content type of the file. You can use constants defined in
ContentType
class. Set this to null or empty string to try to
automatically detect the mime type from the file. If the mime type can't
be detected, application/octet-stream
will be used by defaultMultipartUploadRequest
FileNotFoundException
- if the file does not exist at the specified pathIllegalArgumentException
- if one or more parameters are not validpublic MultipartUploadRequest addFileToUpload(String path, String parameterName, String fileName) throws FileNotFoundException, IllegalArgumentException
addFileToUpload(String, String, String, String)
.path
- Absolute path to the file that you want to uploadparameterName
- Name of the form parameter that will contain file's datafileName
- File name seen by the server side script. If null, the original file name
will be usedMultipartUploadRequest
FileNotFoundException
- if the file does not exist at the specified pathIllegalArgumentException
- if one or more parameters are not validpublic MultipartUploadRequest addFileToUpload(String path, String parameterName) throws FileNotFoundException, IllegalArgumentException
addFileToUpload(String, String, String, String)
path
- Absolute path to the file that you want to uploadparameterName
- Name of the form parameter that will contain file's dataMultipartUploadRequest
FileNotFoundException
- if the file does not exist at the specified pathIllegalArgumentException
- if one or more parameters are not validpublic MultipartUploadRequest setNotificationConfig(UploadNotificationConfig config)
HttpUploadRequest
setNotificationConfig
in class HttpUploadRequest
config
- the upload configuration object or null if you don't want a notification
to be displayedHttpUploadRequest
public MultipartUploadRequest setAutoDeleteFilesAfterSuccessfulUpload(boolean autoDeleteFiles)
HttpUploadRequest
setAutoDeleteFilesAfterSuccessfulUpload
in class HttpUploadRequest
autoDeleteFiles
- true to auto delete files included in the
request when the upload is completed successfully.
By default this setting is set to false, and nothing gets deleted.HttpUploadRequest
public MultipartUploadRequest addHeader(String headerName, String headerValue)
HttpUploadRequest
addHeader
in class HttpUploadRequest
headerName
- header nameheaderValue
- header valueHttpUploadRequest
public MultipartUploadRequest setBasicAuth(String username, String password)
HttpUploadRequest
setBasicAuth
in class HttpUploadRequest
username
- HTTP Basic Auth usernamepassword
- HTTP Basic Auth passwordHttpUploadRequest
public MultipartUploadRequest addParameter(String paramName, String paramValue)
HttpUploadRequest
addParameter
in class HttpUploadRequest
paramName
- parameter nameparamValue
- parameter valueHttpUploadRequest
public MultipartUploadRequest addArrayParameter(String paramName, String... array)
HttpUploadRequest
addArrayParameter
in class HttpUploadRequest
paramName
- parameter namearray
- valuesHttpUploadRequest
public MultipartUploadRequest addArrayParameter(String paramName, List<String> list)
HttpUploadRequest
addArrayParameter
in class HttpUploadRequest
paramName
- parameter namelist
- valuesHttpUploadRequest
public MultipartUploadRequest setMethod(String method)
HttpUploadRequest
setMethod
in class HttpUploadRequest
method
- new HTTP method to useHttpUploadRequest
public MultipartUploadRequest setCustomUserAgent(String customUserAgent)
HttpUploadRequest
setCustomUserAgent
in class HttpUploadRequest
customUserAgent
- custom user agent stringHttpUploadRequest
public MultipartUploadRequest setMaxRetries(int maxRetries)
HttpUploadRequest
setMaxRetries
in class HttpUploadRequest
maxRetries
- number of maximum retries on errorHttpUploadRequest
public MultipartUploadRequest setUsesFixedLengthStreamingMode(boolean fixedLength)
HttpUploadRequest
HttpUploadTask.getBodyLength()
will be automatically used to properly set the
underlying HttpURLConnection
, otherwise chunked streaming mode will be used.setUsesFixedLengthStreamingMode
in class HttpUploadRequest
fixedLength
- true to use fixed length streaming mode (this is the default setting) or
false to use chunked streaming mode.HttpUploadRequest
public MultipartUploadRequest setUtf8Charset()