public class BoxMultipartRequest extends BoxAPIRequest
Used to make HTTP multipart requests to the Box API.
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() . |
protected MediaType |
getPartContentType(String filename) |
protected String |
getPartName() |
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 |
writeMethodWithBody(Request.Builder requestBuilder,
ProgressListener progressListener) |
addHeader, getBody, getConnectTimeout, getMethod, getReadTimeout, getUrl, isRequestRetryable, isResponseRetryable, mediaType, send, send, sendWithoutRetry, setBody, setConnectTimeout, setFollowRedirects, setReadTimeout, setUrl, shouldAuthenticate, toString
protected static final String BOUNDARY
public BoxMultipartRequest(BoxAPIConnection api, URL url)
api
- an API connection for authenticating the request.url
- the URL of the request.protected String getPartName()
protected MediaType getPartContentType(String filename)
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. If the file content is coming from the dynamic stream,
and it's full size cannot be determined on starting upload use fizeSize=-1
or use AbstractBoxMultipartRequest.setFile(InputStream, String)
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 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 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
protected void writeMethodWithBody(Request.Builder requestBuilder, ProgressListener progressListener)
writeMethodWithBody
in class BoxAPIRequest