FilesModule
public class FilesModule
Provides File management.
-
Get information about a file.
Declaration
Parameters
fileIdThe ID of the file on which to retrieve information.
fieldscompletionReturns a standard file object or an error if the fileId is invalid or the user doesn’t have access to the file.
-
update(fileId:name:description:parentId:sharedLink:tags:collections:lock:ifMatch:fields:completion:)Update the information about a file, including renaming or moving the file.
Declaration
Swift
public func update( fileId: String, name: String? = nil, description: String? = nil, parentId: String? = nil, sharedLink: NullableParameter<SharedLinkData>? = nil, tags: [String]? = nil, collections: [String]? = nil, lock: NullableParameter<LockData>? = nil, ifMatch: String? = nil, fields: [String]? = nil, completion: @escaping Callback<File> )Parameters
fileIdThe ID of the file on which to perform the update.
updateFileInfoThe new values with which to update the file.
ifMatchThis is in the ‘etag’ field of the file object, which can be included to prevent race conditions.
fieldscompletionReturns a standard file object or an error if the fileId is invalid or the user doesn’t have access to the file.
-
Create a copy of a file in another folder. The original version of the file will not be altered.
Declaration
Parameters
fileIdThe ID of the source file to copy.
parentIdThe ID of the destination folder.
nameAn optional new name for the file. Box supports file names of 255 characters or less. Names containing non-printable ASCII characters,
/
or\
, names with trailing spaces, and the special names “.” and “..” are also not allowed.versionAn optional file version ID if you want to copy a specific file version
fieldscompletionReturns a standard file object or an error if the fileId is invalid or the update is not successful. An error will be returned if the destination folder is invalid or if a file name collision occurs.
-
Upload a file to a specified folder.
Declaration
Parameters
nameThe name of the file. Box supports file names of 255 characters or less. Names containing non-printable ASCII characters,
/
or\
, names with trailing spaces, and the special names “.” and “..” are also not allowed.parentIdThe ID of the parent folder. Use
0
for the root folder.progressShows the progress of the upload
performPreflightCheckDefines whether to first perform prelfight check request to decide whether file of this size can be uploaded and whether specified name is unique and won’t cause conflicts.
completionReturns a standard file object or an error if the parentId is invalid or if a file name collision occurs.
-
Upload a file to a specified folder.
Declaration
Parameters
fileIdThe ID of the file
nameThe name of the file. Box supports file names of 255 characters or less. Names containing non-printable ASCII characters,
/
or\
, names with trailing spaces, and the special names “.” and “..” are also not allowed.progressShows the progress of the upload
performPreflightCheckChecks whether new file version will be accepted before whole new version is uploaded.
completionReturns a standard file object or an error.
-
Upload a file to a specified folder.
Declaration
Parameters
streamAn InputStream of data for been uploaded.
dataLengthThe lenght of the InputStream
parentIdThe ID of the parent folder. Use
0
for the root folder.nameThe name of the file. Box supports file names of 255 characters or less. Names containing non-printable ASCII characters,
/
or\
, names with trailing spaces, and the special names “.” and “..” are also not allowed.progressShows the progress of the upload
performPreflightCheckDefines whether to perform preflight request first check to see whether uploaded file parameters such as size and name won’t cause an upload error.
completionReturns a standard file object or an error if the parentId is invalid or if a file name collision occurs.
-
Verifies that new file will be accepted by Box before you send all the bytes over the wire. Verifies all permissions as if the file was actually uploaded including: folder upload permission, file name collisions, file size caps, folder and file name restrictions, folder and account storage quota.
Declaration
Swift
public func preflightCheck( name: String, parentId: String, size: Int64? = nil, completion: @escaping Callback<Void> )Parameters
nameThe name of the file
parantIdThe ID of the parent folder. Use
0
for the root folder.sizeThe size of the file in bytes
completionReturns a empty resppnse in case of the checks have been passed and user can proceed to make a upload call or an error.
-
Verifies that an updated file will be accepted by Box before you send all the bytes over the wire. It’s used before uploading new versions of an existing File. Verifies all permissions as if the file was actually uploaded including: folder upload permission, file name collisions, file size caps, folder and file name restrictions, folder and account storage quota.
Declaration
Swift
public func preflightCheckForNewVersion( forFile fileId: String, name: String? = nil, size: Int64? = nil, completion: @escaping Callback<Void> )Parameters
fileIdThe ID of the updated file.
nameThe name of the file.
parantIdThe ID of the parent folder. Use
0
for the root folder.sizeThe size of the file in bytes
completionReturns a empty response in case of the checks have been passed and user can proceed to make a upload call or an error.
-
Declaration
Parameters
fileIdThe ID of the file
expiresAtThe time the lock expires
isDownloadPreventedWhether or not the file can be downloaded while locked
fieldscompletionReturns a standard file object or an error
-
Unlock a file.
Declaration
Parameters
fileIdThe ID of the file
fieldscompletionReturns a standard file object or an error
-
Declaration
Swift
public func getThumbnail( forFile fileId: String, extension: ThumbnailExtension, minHeight: Int? = nil, minWidth: Int? = nil, maxHeight: Int? = nil, maxWidth: Int? = nil, completion: @escaping Callback<Data> )Parameters
fileIdThe ID of the file
extensionSpecifies the thumbnail image file extension
minHeightThe minimum height of the thumbnail
minWidthThe minimum width of the thumbnail
maxHeightThe maximum height of the thumbnail
maxWidthThe maximum width of the thumbnail
-
Get a URL for creating an embedded preview session.
Declaration
Swift
public func getEmbedLink( forFile fileId: String, completion: @escaping Callback<ExpiringEmbedLink> )Parameters
fileIdThe ID of the file
fieldscompletionReturns a standard embed link or an error
-
Get all of the collaborations on a file (i.e. all of the users that have access to that file).
Declaration
Swift
public func listCollaborations( forFile fileId: String, marker: String? = nil, limit: Int? = nil, fields: [String]? = nil ) -> PaginationIterator<Collaboration>Parameters
fileIdThe ID of the file
markerThe position marker at which to begin the response. See marker-based paging for details. This parameter cannot be used simultaneously with the ‘offset’ parameter.
limitThe maximum number of items to return
fields -
Get all of the comments on a file.
Declaration
Swift
public func listComments( forFile fileId: String, offset: Int?, limit: Int?, fields: [String]? = nil ) -> PaginationIterator<Comment>Parameters
fileIdThe ID of the file
offsetThe offset of the item at which to begin the response. See offset-based paging for details. This parameter cannot be used simultaneously with the ‘marker’ parameter.
limitThe maximum number of items to return.
fieldsReturn Value
Returns all of the comments on the file using offset-based paging.
-
Get all of the tasks for a file.
Declaration
Swift
public func listTasks( forFile fileId: String, fields: [String]? = nil ) -> PaginationIterator<Task>Parameters
fileIdThe ID of the file
fieldscompletionReturns all of the tasks on the file
-
Download a file to a specified folder.
Declaration
Swift
public func download( fileId: String, destinationURL: URL, version: String? = nil, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<Void> )Parameters
fileIdThe ID of the file
destinationURLA URL for the location on device that we want to store the file once been donwloaded
versionOptional file version ID to download (defaults to the current version)
progressShows the progress of the upload
completionReturns an empty response or an error
-
Discards a file to the trash. The
etagof the file can be included as an ‘If-Match’ header to prevent race conditions. Depending on the enterprise settings for this user, the item will either be actually deleted from Box or moved to the trash.Declaration
Swift
public func delete( fileId: String, ifMatch: String? = nil, completion: @escaping Callback<Void> )Parameters
fileIdId of the file that should be deleted.
ifMatchThe etag of the file. This is in the
etagfield of the file object.completionEmpty response in case of success or an error.
-
Retrieves all file versions on a specified file.
Declaration
Swift
public func listVersions( fileId: String, offset: Int? = nil, limit: Int? = nil, fields: [String]? = nil ) -> PaginationIterator<FileVersion>Parameters
fileIdThe id to retrieve all versions on.
offsetThe offset of the item at which to begin the response. See offset-based paging for details.
limitThe maximum number of items to return. The default is 100 and the maximum is 1,000.
fieldsComma-separated list of fields to include in the response.
-
Retrieves a specified file version.
Declaration
Swift
public func getVersion( fileId: String, fileVersionId: String, fields: [String]? = nil, completion: @escaping Callback<FileVersion> )Parameters
fileIdThe id the file the file version belongs to.
fieldVersionIdThe id of the file version to retrieve.
fieldsComma-separated list of fields to include in the response.
completionReturns a full file version object or an error.
-
Promotes the specified file version to the current file version.
Declaration
Swift
public func promoteVersion( fileId: String, fileVersionId: String, fields: [String]? = nil, completion: @escaping Callback<FileVersion> )Parameters
fileIdThe id of the file the file version to promote belongs to.
fileVersionIdThe id of the file version to promote.
fieldsComma-separated list of fields to include in the response.
completionReturns a full file version object or an error.
-
Discards the specified file version to the trash.
Declaration
Swift
public func deleteVersion( fileId: String, fileVersionId: String, ifMatch: String? = nil, completion: @escaping Callback<Void> )Parameters
fileIdThe id of the file the file version to delete belongs to.
fileVersionIdThe file version to delete.
ifMatchThe
etagof the file version. This is unique to the file version and prevents simultaneous updates.completionReturns a empty reponse or an error.
-
Remove the watermark from a specified file.
Declaration
Swift
public func removeWatermark( fileId: String, completion: @escaping Callback<Void> )Parameters
fileIdThe id of the file to remove the watermark from.
completionReturns an empty response or an error.
-
Gets file with updated shared link
Declaration
Swift
public func getSharedLink( forFile fileId: String, completion: @escaping Callback<SharedLink> )Parameters
fileIdThe ID of the file
completionReturns a standard SharedLink object or an error
-
Creates of updates shared link for a file
Declaration
Swift
public func setSharedLink( forFile fileId: String, unsharedAt: NullableParameter<Date>? = nil, access: SharedLinkAccess? = nil, password: NullableParameter<String>? = nil, canDownload: Bool? = nil, completion: @escaping Callback<SharedLink> )Parameters
fileIdThe ID of the file
stopSharingAtThe date-time that this link will become disabled. This field can only be set by users with paid accounts
accessThe level of access. If you omit this field then the access level will be set to the default access level specified by the enterprise admin
passwordThe password required to access the shared link. Set to .empty to delete the password
canDownloadWhether the shared link allows downloads
completionReturns a standard SharedLink object or an error
-
Removes shared link for a file
Declaration
Swift
public func deleteSharedLink( forFile fileId: String, completion: @escaping Callback<Void> )Parameters
fileIdThe ID of the file
completionReturns an empty response or an error
-
Create an upload session for uploading a new file.
Declaration
Swift
func createUploadSession( folderId: String, fileName: String, fileSize: Int32, completion: @escaping Callback<UploadSession> )Parameters
folderIdThe ID of the folder that will contain the new file.
fileNameName of new file.
fileSizeThe total number of bytes in the file to be uploaded.
completionReturns a upload session object or an error if upload session cannot be created, for example when folder with specified ID doesn’t exist
-
Create an upload session for uploading a new file version.
Declaration
Swift
func createUploadSessionForNewVersion( ofFile fileId: String, fileName: String? = nil, fileSize: Int32, completion: @escaping Callback<UploadSession> )Parameters
fileIdThe ID of the file of which version is uploaded.
fileNameOptional name of new file. If provided, the file name will be changed to this value upon successful upload.
fileSizeThe total number of bytes in the file to be uploaded.
completionReturns a upload session object or an error if upload session cannot be created
-
Upload a part of the file to this session.
Declaration
Swift
func uploadPart( sessionId: String, data: Data, offset: Int, totalSize: Int, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<UploadPart> )Parameters
sessionIdID of upload session object.
dataThe part content as binary data.
offsetThe first byte of uploaded part
totalSizetotal size of uploaded data
progressClosure where upload progress will be reported
completionReturns a upload part object or an error if part upload failed
-
Get list of parts of chunked upload session.
Declaration
Swift
func listUploadSessionParts( sessionId: String, offset: Int? = nil, limit: Int? = nil ) -> OffsetPaginationIterator<UploadPartDescription>Parameters
sessionIdID of upload session object.
offsetThe offset of the item at which to begin the response. See offset-based paging for details.
limitThe maximum number of items to return. The default is 100 and the maximum is 1,000.
-
commitUpload(sessionId:parts:sha1:description:sharedLink:tags:collections:lock:contentCreatedAt:contentModifiedAt:completion:)Commit upload session after successful upload of all parts.
Declaration
Swift
func commitUpload( sessionId: String, parts: [UploadPartDescription], sha1: String, description: String? = nil, sharedLink: SharedLinkData? = nil, tags: [String]? = nil, collections: [String]? = nil, lock: LockData? = nil, contentCreatedAt: Date? = nil, contentModifiedAt: Date? = nil, completion: @escaping Callback<File> )Parameters
sessionIdID of upload session object.
partsArray of upload part descriptions
sha1Base64 encoded SHA1 digest from the whole uploaded file.
descriptionOptional. The description of this file.
sharedLinkOptional. The shared link object for this file.
tagsOptional. All tags applied to this file
collectionsOptional. The collections that the file belongs to
lockOptional. The lock held on this file. If there is no lock, this can either be null or have a timestamp in the past.
contentCreatedAtOptional. When the content of this file was created.
contentModifiedAtOptional. When the content of this file was last modified.
completionReturns an array of files or an error if part upload failed
-
Abort chunked upload session.
Declaration
Swift
func abortUpload( sessionId: String, completion: @escaping Callback<Void> )Parameters
sessionIdID of upload session object.
completionReturns a success or an error if aborting failed
-
Get chunked upload session with ID.
Declaration
Swift
func getUploadSession( sessionId: String, completion: @escaping Callback<UploadSession> )Parameters
sessionIdID of existing chunked upload session.
completionReturns a upload session or an error if session cannot be returned
-
Get representations for a file.
Declaration
Swift
func listRepresentations( fileId: String, representationHint: FileRepresentationHint? = nil, completion: @escaping Callback<[FileRepresentation]> )Parameters
fileIdThe id of the file to retrieve representations for.
representationHintThe representation to retrieve for the file. It can be one of predefined options or custom representation, see representation documentation.
completionReturns an array of the specified representations.
-
Get particular representation for a file.
Declaration
Swift
func getRepresentationContent( fileId: String, representationHint: FileRepresentationHint, assetPath: String = "", destinationURL: URL, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<Void> )Parameters
fileIdThe id of the file to retrieve representations for.
representationHintThe representation to retrieve for the file. It can be one of predefined options or custom representation. If multiple representations match the representationHint, the behavior is undefined - used representation is selected nondeterministically. See representation documentation.
assetPathAsset path for representations with multiple files
destinationURLA URL for the location on device that we want to store the file once been donwloaded
completionReturns an array of the specified representations.
-
Download a file to a specified folder.
Declaration
Swift
public func downloadRepresentation( sourceURL: URL, destinationURL: URL, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<Void> )Parameters
fileIdThe ID of the file
destinationURLA URL for the location on device that we want to store the file once been donwloaded
versionOptional file version ID to download (defaults to the current version)
progressShows the progress of the upload
completionReturns an empty response or an error
-
Retrieves information about a file version retention policy.
Declaration
Swift
func getVersionRetention( retentionId id: String, completion: @escaping Callback<FileVersionRetention> )Parameters
idIdentifier of retention policy of a file version.
completionEither specified file version retention will be returned upon success or an error.
-
listVersionRetentions(fileId:fileVersionId:policyId:dispositionAction:dispositionBefore:dispositionAfter:limit:marker:)Retrieves all file version retentions for the given enterprise.
Declaration
Swift
func listVersionRetentions( fileId: String? = nil, fileVersionId: String? = nil, policyId: String? = nil, dispositionAction: DispositionAction? = nil, dispositionBefore: Date? = nil, dispositionAfter: Date? = nil, limit: Int? = nil, marker: String? = nil ) -> PaginationIterator<FileVersionRetention>Parameters
fileIdA file id to filter the file version retentions by.
fileVersionIdA file version id to filter the file version retentions by.
policyIdA policy id to filter the file version retentions by.
dispositionActionThe disposition action of the retention policy.
dispositionBeforeFilter retentions with disposition date before provided date.
dispositionAfterFilter retentions with disposition date after provided date.
limitThe maximum number of items to return in a page.
markerThe position marker at which to begin the response. See marker-based paging for details.
Return Value
Returns either the list of all file version retentions for the enterprise or an error. If optional parameters are given, only the file version retentions that match the query parameters are returned.
FilesModule Class Reference