@BoxResourceType(value="file") public class BoxFile extends BoxItem
Unless otherwise noted, the methods in this class can throw an unchecked BoxAPIException
(unchecked
meaning that the compiler won't force you to handle it) if an error occurs. If you wish to implement custom error
handling for errors related to the Box REST API, you should capture this exception explicitly.
Modifier and Type | Class and Description |
---|---|
class |
BoxFile.Info
Contains information about a BoxFile.
|
static class |
BoxFile.Permission
Enumerates the possible permissions that a user can have on a file.
|
static class |
BoxFile.ThumbnailFileType
Used to specify what filetype to request for a file thumbnail.
|
Modifier and Type | Field and Description |
---|---|
static String[] |
ALL_FIELDS
An array of all possible file fields that can be requested when calling
getInfo() . |
Constructor and Description |
---|
BoxFile(BoxAPIConnection api,
String id)
Constructs a BoxFile for a file with a given ID.
|
Modifier and Type | Method and Description |
---|---|
BoxComment.Info |
addComment(String message)
Adds a comment to this file.
|
BoxTask.Info |
addTask(BoxTask.Action action,
String message,
Date dueAt)
Adds a new task to this file.
|
BoxWebHook.Info |
addWebHook(URL address,
BoxWebHook.Trigger... triggers)
Adds new
BoxWebHook to this BoxFile . |
BoxWatermark |
applyWatermark()
Used to apply or update the watermark for the file.
|
void |
canUploadVersion(String name,
long fileSize,
String parentID)
Checks if the file can be successfully uploaded by using the preflight check.
|
BoxCollaboration.Info |
collaborate(BoxCollaborator collaborator,
BoxCollaboration.Role role,
Boolean notify,
Boolean canViewPath)
Adds a collaborator to this file.
|
BoxCollaboration.Info |
collaborate(String email,
BoxCollaboration.Role role,
Boolean notify,
Boolean canViewPath)
Adds a collaborator to this folder.
|
BoxFile.Info |
copy(BoxFolder destination)
Copies this item to another folder.
|
BoxFile.Info |
copy(BoxFolder destination,
String newName)
Copies this item to another folder and gives it a new name.
|
Metadata |
createMetadata(Metadata metadata)
Creates metadata on this file in the global properties template.
|
Metadata |
createMetadata(String typeName,
Metadata metadata)
Creates metadata on this file in the specified template type.
|
Metadata |
createMetadata(String typeName,
String scope,
Metadata metadata)
Creates metadata on this file in the specified template type.
|
BoxSharedLink |
createSharedLink(BoxSharedLink.Access access,
Date unshareDate,
BoxSharedLink.Permissions permissions)
Creates a new shared link for this item.
|
BoxFileUploadSession.Info |
createUploadSession(long fileSize)
Creates an upload session to create a new version of a file in chunks.
|
void |
delete()
Deletes this file by moving it to the trash.
|
void |
deleteMetadata()
Deletes the file properties metadata.
|
void |
deleteMetadata(String typeName)
Deletes the file metadata of specified template type.
|
void |
deleteMetadata(String typeName,
String scope)
Deletes the file metadata of specified template type.
|
void |
download(OutputStream output)
Downloads the contents of this file to a given OutputStream.
|
void |
download(OutputStream output,
ProgressListener listener)
Downloads the contents of this file to a given OutputStream while reporting the progress to a ProgressListener.
|
void |
downloadRange(OutputStream output,
long offset)
Downloads a part of this file's contents, starting at specified byte offset.
|
void |
downloadRange(OutputStream output,
long rangeStart,
long rangeEnd)
Downloads a part of this file's contents, starting at rangeStart and stopping at rangeEnd.
|
void |
downloadRange(OutputStream output,
long rangeStart,
long rangeEnd,
ProgressListener listener)
Downloads a part of this file's contents, starting at rangeStart and stopping at rangeEnd, while reporting the
progress to a ProgressListener.
|
BoxResourceIterable<BoxCollaboration.Info> |
getAllFileCollaborations(String... fields)
Used to retrieve all collaborations associated with the item.
|
Iterable<Metadata> |
getAllMetadata(String... fields)
Used to retrieve all metadata associated with the file.
|
List<BoxComment.Info> |
getComments()
Gets a list of any comments on this file.
|
URL |
getDownloadURL()
Gets an expiring URL for downloading a file directly from Box.
|
BoxFile.Info |
getInfo()
Gets information about this item.
|
BoxFile.Info |
getInfo(String... fields)
Gets information about this item that's limited to a list of specified fields.
|
protected URL |
getItemURL() |
Metadata |
getMetadata()
Gets the file properties metadata.
|
Metadata |
getMetadata(String typeName)
Gets the file metadata of specified template type.
|
Metadata |
getMetadata(String typeName,
String scope)
Gets the file metadata of specified template type.
|
URL |
getPreviewLink()
Gets an expiring URL for creating an embedded preview session.
|
List<BoxTask.Info> |
getTasks()
Gets a list of any tasks on this file.
|
byte[] |
getThumbnail(BoxFile.ThumbnailFileType fileType,
int minWidth,
int minHeight,
int maxWidth,
int maxHeight)
Retrieves a thumbnail, or smaller image representation, of this file.
|
Collection<BoxFileVersion> |
getVersions()
Gets any previous versions of this file.
|
BoxWatermark |
getWatermark(String... fields)
Used to retrieve the watermark for the file.
|
BoxLock |
lock(Date expiresAt)
Locks a file.
|
BoxLock |
lock(Date expiresAt,
boolean isDownloadPrevented)
Locks a file.
|
BoxItem.Info |
move(BoxFolder destination)
Moves this item to another folder.
|
BoxItem.Info |
move(BoxFolder destination,
String newName)
Moves this item to another folder and gives it a new name.
|
void |
removeWatermark()
Removes a watermark from the file.
|
void |
rename(String newName)
Renames this file.
|
BoxFile.Info |
setCollections(BoxCollection... collections)
Sets the collections that this item belongs to.
|
void |
unlock()
Unlocks a file.
|
void |
updateInfo(BoxFile.Info info)
Updates the information about this file with any info fields that have been modified locally.
|
Metadata |
updateMetadata(Metadata metadata)
Updates the file metadata.
|
BoxFile.Info |
uploadLargeFile(InputStream inputStream,
long fileSize)
Creates a new version of a file.
|
BoxFile.Info |
uploadLargeFile(InputStream inputStream,
long fileSize,
int nParallelConnections,
long timeOut,
TimeUnit unit)
Creates a new version of a file using specified number of parallel http connections.
|
void |
uploadVersion(InputStream fileContent)
Uploads a new version of this file, replacing the current version.
|
void |
uploadVersion(InputStream fileContent,
Date modified,
long fileSize,
ProgressListener listener)
Uploads a new version of this file, replacing the current version, while reporting the progress to a
ProgressListener.
|
void |
uploadVersion(InputStream fileContent,
String fileContentSHA1)
Uploads a new version of this file, replacing the current version.
|
void |
uploadVersion(InputStream fileContent,
String fileContentSHA1,
Date modified)
Uploads a new version of this file, replacing the current version.
|
void |
uploadVersion(InputStream fileContent,
String fileContentSHA1,
Date modified,
long fileSize,
ProgressListener listener)
Uploads a new version of this file, replacing the current version, while reporting the progress to a
ProgressListener.
|
applyWatermark, getSharedItem, getSharedItem, getWatermark, removeWatermark
equals, getAPI, getID, getResourceType, hashCode
public static final String[] ALL_FIELDS
getInfo()
.public BoxFile(BoxAPIConnection api, String id)
api
- the API connection to be used by the file.id
- the ID of the file.protected URL getItemURL()
getItemURL
in class BoxItem
public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions)
BoxItem
This method is a convenience method for manually creating a new shared link and applying it to this item with
BoxItem.Info.setSharedLink(com.box.sdk.BoxSharedLink)
. You may want to create the shared link manually so that it can be updated along with
other changes to the item's info in a single network request, giving a boost to performance.
createSharedLink
in class BoxItem
access
- the access level of the shared link.unshareDate
- the date and time at which the link will expire. Can be null to create a non-expiring link.permissions
- the permissions of the shared link. Can be null to use the default permissions.public BoxWebHook.Info addWebHook(URL address, BoxWebHook.Trigger... triggers)
BoxWebHook
to this BoxFile
.address
- BoxWebHook.Info.getAddress()
triggers
- BoxWebHook.Info.getTriggers()
BoxWebHook.Info
public BoxComment.Info addComment(String message)
message
- the comment's message.public BoxTask.Info addTask(BoxTask.Action action, String message, Date dueAt)
action
- the action the task assignee will be prompted to do.message
- an optional message to include with the task.dueAt
- the day at which this task is due.public URL getDownloadURL()
public void download(OutputStream output)
output
- the stream to where the file will be written.public void download(OutputStream output, ProgressListener listener)
output
- the stream to where the file will be written.listener
- a listener for monitoring the download's progress.public void downloadRange(OutputStream output, long offset)
output
- the stream to where the file will be written.offset
- the byte offset at which to start the download.public void downloadRange(OutputStream output, long rangeStart, long rangeEnd)
output
- the stream to where the file will be written.rangeStart
- the byte offset at which to start the download.rangeEnd
- the byte offset at which to stop the download.public void downloadRange(OutputStream output, long rangeStart, long rangeEnd, ProgressListener listener)
output
- the stream to where the file will be written.rangeStart
- the byte offset at which to start the download.rangeEnd
- the byte offset at which to stop the download.listener
- a listener for monitoring the download's progress.public BoxFile.Info copy(BoxFolder destination)
BoxItem
public BoxFile.Info copy(BoxFolder destination, String newName)
BoxItem
public void delete()
public BoxItem.Info move(BoxFolder destination)
BoxItem
public BoxItem.Info move(BoxFolder destination, String newName)
BoxItem
public void rename(String newName)
newName
- the new name of the file.public BoxFile.Info getInfo()
BoxItem
public BoxFile.Info getInfo(String... fields)
BoxItem
public void updateInfo(BoxFile.Info info)
The only fields that will be updated are the ones that have been modified locally. For example, the following code won't update any information (or even send a network request) since none of the info's fields were changed:
BoxFile file = new File(api, id); BoxFile.Info info = file.getInfo(); file.updateInfo(info);
info
- the updated info.public Collection<BoxFileVersion> getVersions()
public void canUploadVersion(String name, long fileSize, String parentID)
name
- the name to give the uploaded file or null to use existing name.fileSize
- the size of the file used for account capacity calculations.parentID
- the ID of the parent folder that the new version is being uploaded to.public void uploadVersion(InputStream fileContent)
fileContent
- a stream containing the new file contents.public void uploadVersion(InputStream fileContent, String fileContentSHA1)
fileContent
- a stream containing the new file contents.fileContentSHA1
- a string containing the SHA1 hash of the new file contents.public void uploadVersion(InputStream fileContent, String fileContentSHA1, Date modified)
fileContent
- a stream containing the new file contents.fileContentSHA1
- a string containing the SHA1 hash of the new file contents.modified
- the date that the new version was modified.public void uploadVersion(InputStream fileContent, Date modified, long fileSize, ProgressListener listener)
fileContent
- a stream containing the new file contents.modified
- the date that the new version was modified.fileSize
- the size of the file used for determining the progress of the upload.listener
- a listener for monitoring the upload's progress.public void uploadVersion(InputStream fileContent, String fileContentSHA1, Date modified, long fileSize, ProgressListener listener)
fileContent
- a stream containing the new file contents.fileContentSHA1
- the SHA1 hash of the file contents. will be sent along in the Content-MD5 headermodified
- the date that the new version was modified.fileSize
- the size of the file used for determining the progress of the upload.listener
- a listener for monitoring the upload's progress.public URL getPreviewLink()
public byte[] getThumbnail(BoxFile.ThumbnailFileType fileType, int minWidth, int minHeight, int maxWidth, int maxHeight)
fileType
- either PNG of JPGminWidth
- minimum widthminHeight
- minimum heightmaxWidth
- maximum widthmaxHeight
- maximum heightpublic List<BoxComment.Info> getComments()
public List<BoxTask.Info> getTasks()
public Metadata createMetadata(Metadata metadata)
metadata
- The new metadata values.public Metadata createMetadata(String typeName, Metadata metadata)
typeName
- the metadata template type name.metadata
- the new metadata values.public Metadata createMetadata(String typeName, String scope, Metadata metadata)
typeName
- the metadata template type name.scope
- the metadata scope (global or enterprise).metadata
- the new metadata values.public BoxLock lock(Date expiresAt)
expiresAt
- expiration date of the lock.public BoxLock lock(Date expiresAt, boolean isDownloadPrevented)
expiresAt
- expiration date of the lock.isDownloadPrevented
- is downloading of file prevented when locked.public void unlock()
public Iterable<Metadata> getAllMetadata(String... fields)
fields
- the optional fields to retrieve.public Metadata getMetadata()
public Metadata getMetadata(String typeName)
typeName
- the metadata template type name.public Metadata getMetadata(String typeName, String scope)
typeName
- the metadata template type name.scope
- the metadata scope (global or enterprise).public Metadata updateMetadata(Metadata metadata)
metadata
- the new metadata values.public void deleteMetadata()
public void deleteMetadata(String typeName)
typeName
- the metadata template type name.public void deleteMetadata(String typeName, String scope)
typeName
- the metadata template type name.scope
- the metadata scope (global or enterprise).public BoxWatermark getWatermark(String... fields)
fields
- the fields to retrieve.public BoxWatermark applyWatermark()
public void removeWatermark()
public BoxFile.Info setCollections(BoxCollection... collections)
setCollections
in class BoxItem
collections
- the collections that this item should belong to.public BoxFileUploadSession.Info createUploadSession(long fileSize)
fileSize
- the size of the file that will be uploaded.public BoxFile.Info uploadLargeFile(InputStream inputStream, long fileSize) throws InterruptedException, IOException
inputStream
- the stream instance that contains the data.fileSize
- the size of the file that will be uploaded.InterruptedException
- when a thread execution is interrupted.IOException
- when reading a stream throws exception.public BoxFile.Info uploadLargeFile(InputStream inputStream, long fileSize, int nParallelConnections, long timeOut, TimeUnit unit) throws InterruptedException, IOException
inputStream
- the stream instance that contains the data.fileSize
- the size of the file that will be uploaded.nParallelConnections
- number of parallel http connections to usetimeOut
- time to wait before killing the jobunit
- time unit for the time wait valueInterruptedException
- when a thread execution is interrupted.IOException
- when reading a stream throws exception.public BoxCollaboration.Info collaborate(BoxCollaborator collaborator, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath)
collaborator
- the collaborator to add.role
- the role of the collaborator.notify
- determines if the user (or all the users in the group) will receive email notifications.canViewPath
- whether view path collaboration feature is enabled or not.public BoxCollaboration.Info collaborate(String email, BoxCollaboration.Role role, Boolean notify, Boolean canViewPath)
email
- the email address of the collaborator to add.role
- the role of the collaborator.notify
- determines if the user (or all the users in the group) will receive email notifications.canViewPath
- whether view path collaboration feature is enabled or not.public BoxResourceIterable<BoxCollaboration.Info> getAllFileCollaborations(String... fields)
fields
- the optional fields to retrieve.