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: dispositionAt: 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, dispositionAt: Date? = nil, ifMatch: String? = nil, fields: [String]? = nil, completion: @escaping Callback<File> )Parameters
fileIdThe ID of the file on which to perform the update.
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.
descriptionThe description of the file.
parentIdThe ID of the parent folder.
sharedLinkShared links provide direct, read-only access to file on Box using a URL.
tagsArray of tags to be added or replaced to the file
collectionsList of collection identifiers to which the file membership will be set.
lockDefines a lock on an item. This prevents the item from being moved, renamed, or otherwise changed by anyone other than the user who created the lock. Set this to null to remove the lock.
dispositionAtThe retention expiration timestamp for the given file. This date cannot be shortened once set on a 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
Swift
@discardableResult public func upload( data: Data, name: String, parentId: String, progress: @escaping (Progress) -> Void = { _ in }, performPreflightCheck: Bool = false, completion: @escaping Callback<File> ) -> BoxUploadTaskParameters
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.
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.
Return Value
BoxUploadTask
-
uploadVersion(forFile:name: contentModifiedAt: data: ifMatch: progress: performPreflightCheck: completion: ) Upload a file to a specified folder.
Declaration
Swift
@discardableResult public func uploadVersion( forFile fileId: String, name: String? = nil, contentModifiedAt: String? = nil, data: Data, ifMatch: String? = nil, progress: @escaping (Progress) -> Void = { _ in }, performPreflightCheck: Bool = false, completion: @escaping Callback<File> ) -> BoxUploadTaskParameters
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.
ifMatchThe
etagof the old file version. Ensures that the file hasn’t been updated since getting the etag, which could indicate conflicting edits.performPreflightCheckChecks whether new file version will be accepted before whole new version is uploaded.
completionReturns a standard file object or an error.
Return Value
BoxUploadTask
-
Upload a file to a specified folder.
Declaration
Swift
@discardableResult public func streamUpload( stream: InputStream, fileSize: Int, name: String, parentId: String, progress: @escaping (Progress) -> Void = { _ in }, performPreflightCheck: Bool = false, completion: @escaping Callback<File> ) -> BoxUploadTaskParameters
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.
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.
Return Value
BoxUploadTask
-
streamUploadVersion(stream:fileSize: forFile: name: contentModifiedAt: ifMatch: progress: performPreflightCheck: completion: ) Upload a new version of an existing file.
Declaration
Swift
@discardableResult public func streamUploadVersion( stream: InputStream, fileSize: Int, forFile fileId: String, name: String, contentModifiedAt: String? = nil, ifMatch: String? = nil, progress: @escaping (Progress) -> Void = { _ in }, performPreflightCheck: Bool = false, completion: @escaping Callback<File> ) -> BoxUploadTaskParameters
streamAn InputStream of data for the file to be uploaded.
fileSizeThe length of the InputStream
forFileThe 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.
contentModifiedAtThe time the file was last modified. Defaults to time of upload.
ifMatchThe
etagof the file version. Ensures this item hasn’t recently changed before making changes.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.
Return Value
BoxUploadTask
-
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
@discardableResult public func preflightCheck( name: String, parentId: String, size: Int64? = nil, completion: @escaping Callback<Void> ) -> BoxNetworkTaskParameters
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.
Return Value
BoxNetworkTask
-
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
@discardableResult public func preflightCheckForNewVersion( forFile fileId: String, name: String? = nil, size: Int64? = nil, completion: @escaping Callback<Void> ) -> BoxNetworkTaskParameters
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.
Return Value
BoxNetworkTask
-
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 ) -> PagingIterator<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 ) -> PagingIterator<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 ) -> PagingIterator<Task>Parameters
fileIdThe ID of the file
fieldscompletionReturns all of the tasks on the file
-
Download a file to a specified folder.
Declaration
Swift
@discardableResult public func download( fileId: String, destinationURL: URL, version: String? = nil, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<Void> ) -> BoxDownloadTaskParameters
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)
completionReturns an empty response or an error
Return Value
BoxDownloadTask
-
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 ) -> PagingIterator<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, vanityName: NullableParameter<String>? = nil, access: SharedLinkAccess? = nil, password: NullableParameter<String>? = nil, canDownload: Bool? = nil, completion: @escaping Callback<SharedLink> )Parameters
fileIdThe ID of the file
unsharedAtThe date-time that this link will become disabled. This field can only be set by users with paid accounts
vanityNameThe custom name of a shared link, as used in the vanityUrl field. It should be between 12 and 30 characters. This field can contains only letters, numbers, and hyphens.
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
-
Creates a zip of multiple files and folders and downloads it.
Declaration
Swift
public func downloadZip(name: String, items: [ZipDownloadItem], destinationURL: URL, completion: @escaping Callback<ZipDownloadStatus>)Parameters
nameThe name of the zip file to be created
itemsArray of files or folders to be part of the created zip
destinationURLA URL for the location on device that we want to store the file once it has been downloaded
completionReturns a standard ZipDownloadStatus object 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
@discardableResult func uploadPart( sessionId: String, data: Data, offset: Int, totalSize: Int, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<UploadPart> ) -> BoxUploadTaskParameters
sessionIdID of upload session object.
dataThe part content as binary data.
offsetThe first byte of uploaded part
totalSizetotal size of uploaded data
completionReturns a upload part object or an error if part upload failed
Return Value
BoxUploadTask
-
Get list of parts of chunked upload session.
Declaration
Swift
func listUploadSessionParts( sessionId: String, offset: Int? = nil, limit: Int? = nil ) -> PagingIterator<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
@discardableResult public func downloadRepresentation( sourceURL: URL, destinationURL: URL, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping Callback<Void> ) -> BoxDownloadTaskParameters
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)
completionReturns an empty response or an error
Return Value
BoxDownloadTask
-
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
@available(*, deprecated, message: "Please use RetentionPoliciesModule#listFilesUnderRetentionForAssignment(retentionPolicyAssignmentId:limit:marker﹚ instead.") 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 ) -> PagingIterator<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