public class BoxMultipartRequest extends BoxAPIRequest
This class partially implements the HTTP multipart standard in order to upload files to Box. The body of this request type cannot be set directly. Instead, it can be modified by adding multipart fields and setting file contents. The body of multipart requests will not be logged since they are likely to contain binary data.
BoxAPIRequest.RequestHeader
Constructor and Description |
---|
BoxMultipartRequest(BoxAPIConnection api,
URL url)
Constructs an authenticated BoxMultipartRequest using a provided BoxAPIConnection.
|
Modifier and Type | Method and Description |
---|---|
protected String |
bodyToString()
Returns a String representation of this request's body used in
BoxAPIRequest.toString() . |
void |
putField(String key,
Date value)
Adds or updates a multipart field in this request.
|
void |
putField(String key,
String value)
Adds or updates a multipart field in this request.
|
protected void |
resetBody()
Resets the InputStream containing this request's body.
|
void |
setBody(InputStream stream)
This method is unsupported in BoxMultipartRequest.
|
void |
setBody(String body)
This method is unsupported in BoxMultipartRequest.
|
void |
setContentSHA1(String sha1)
Sets the SHA1 hash of the file contents of this request.
|
void |
setFile(InputStream inputStream,
String filename)
Sets the file contents of this request.
|
void |
setFile(InputStream inputStream,
String filename,
long fileSize)
Sets the file contents of this request.
|
void |
setUploadFileCallback(UploadFileCallback callback,
String filename)
Sets the callback which allows file content to be written on output stream.
|
protected void |
writeBody(HttpURLConnection connection,
ProgressListener listener)
Writes the body of this request to an HttpURLConnection.
|
addHeader, getBody, getConnectTimeout, getHeaders, getMethod, getReadTimeout, getUrl, isRequestRetryable, isResponseRetryable, send, send, sendWithoutRetry, setBody, setConnectTimeout, setFollowRedirects, setReadTimeout, toString
public BoxMultipartRequest(BoxAPIConnection api, URL url)
api
- an API connection for authenticating the request.url
- the URL of the request.public void putField(String key, String value)
key
- the field's key.value
- the field's value.public void putField(String key, Date value)
key
- the field's key.value
- the field's value.public void setFile(InputStream inputStream, String filename)
inputStream
- a stream containing the file contents.filename
- the name of the file.public void setFile(InputStream inputStream, String filename, long fileSize)
inputStream
- a stream containing the file contents.filename
- the name of the file.fileSize
- the size of the file.public void setUploadFileCallback(UploadFileCallback callback, String filename)
callback
- the callback which allows file content to be written on output stream.filename
- the size of the file.public void setContentSHA1(String sha1)
sha1
- a string containing the SHA1 hash of the file contents.public void setBody(InputStream stream)
putField
and setFile
methods.setBody
in class BoxAPIRequest
stream
- N/AUnsupportedOperationException
- this method is unsupported.public void setBody(String body)
putField
and setFile
methods.setBody
in class BoxAPIRequest
body
- N/AUnsupportedOperationException
- this method is unsupported.protected void writeBody(HttpURLConnection connection, ProgressListener listener)
BoxAPIRequest
Subclasses overriding this method must remember to close the connection's OutputStream after writing.
writeBody
in class BoxAPIRequest
connection
- the connection to which the body should be written.listener
- an optional listener for monitoring the write progress.protected void resetBody() throws IOException
BoxAPIRequest
This method will be called before each attempt to resend the request, giving subclasses an opportunity to reset any streams that need to be read when sending the body.
resetBody
in class BoxAPIRequest
IOException
- if the stream cannot be reset.protected String bodyToString()
BoxAPIRequest
BoxAPIRequest.toString()
. This method returns
null by default.
A subclass may want override this method if the body can be converted to a String for logging or debugging purposes.
bodyToString
in class BoxAPIRequest