FilesModule
public class FilesModule
Provides File management.
-
Get information about a file.
Declaration
Parameters
fileId
The ID of the file on which to retrieve information.
fields
completion
Returns a standard file object or an error if the fileId is invalid or the user doesn’t have access to the file.
-
Update the information about a file, including renaming or moving the file.
Declaration
Swift
public func updateFileInfo( fileId: String, updateFileInfo: UpdateFileInfoData, ifMatch: String? = nil, fields: [String]? = nil, completion: @escaping (Result<File, BoxError>) -> Void )
Parameters
fileId
The ID of the file on which to perform the update.
updateFileInfo
The new values with which to update the file.
ifMatch
This is in the ‘etag’ field of the file object, which can be included to prevent race conditions.
fields
completion
Returns 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
fileId
The ID of the source file to copy.
parentId
The ID of the destination folder.
name
An 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.version
An optional file version ID if you want to copy a specific file version
fields
completion
Returns 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
name
The 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.parentId
The ID of the parent folder. Use
0
for the root folder.progress
Shows the progress of the upload
completion
Returns 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
fileId
The ID of the file
name
The 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.progress
Shows the progress of the upload
completion
Returns a standard file object or an error.
-
Upload a file to a specified folder.
Declaration
Parameters
stream
An InputStream of data for been uploaded.
dataLength
The lenght of the InputStream
parentId
The ID of the parent folder. Use
0
for the root folder.name
The 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.progress
Shows the progress of the upload
completion
Returns a standard file object or an error if the parentId is invalid or if a file name collision occurs.
-
Declaration
Swift
public func preflightCheck( name: String, parentId: String, size: Int64, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
name
The name of the file
parantId
The ID of the parent folder. Use
0
for the root folder.size
The size of the file in bytes
completion
Returns a empty resppnse in case of the checks have been passed and user can proceed to make a upload call or an error.
-
Lock a file.
Declaration
Parameters
fileId
The ID of the file
expiresAt
The time the lock expires
isDownloadPrevented
Whether or not the file can be downloaded while locked
fields
completion
Returns a standard file object or an error
-
Unlock a file.
Declaration
Parameters
fileId
The ID of the file
expiresAt
The time the lock expires
isDownloadPrevented
Whether or not the file can be downloaded while locked
fields
completion
Returns 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 (Result<Data, BoxError>) -> Void )
Parameters
fileId
The ID of the file
extension
Specifies the thumbnail image file extension
minHeight
The minimum height of the thumbnail
minWidth
The minimum width of the thumbnail
maxHeight
The maximum height of the thumbnail
maxWidth
The maximum width of the thumbnail
-
Get a URL for creating an embedded preview session.
Declaration
Swift
public func getEmbedLink( forFile fileId: String, completion: @escaping (Result<ExpiringEmbedLink, BoxError>) -> Void )
Parameters
fileId
The ID of the file
fields
completion
Returns 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 getFileCollaborations( forFile fileId: String, marker: String? = nil, limit: Int?, fields: [String]? = nil ) -> PaginationIterator<Collaboration>
Parameters
fileId
The ID of the file
marker
The position marker at which to begin the response. See marker-based paging for details. This parameter cannot be used simultaneously with the ‘offset’ parameter.
limit
The maximum number of items to return
fields
-
Get all of the comments on a file.
Declaration
Swift
public func getFileComments( forFile fileId: String, offset: Int?, limit: Int?, fields: [String]? = nil ) -> PaginationIterator<Comment>
Parameters
fileId
The ID of the file
offset
The 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.
limit
The maximum number of items to return.
fields
Return 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 getFileTasks( forFile fileId: String, fields: [String]? = nil ) -> PaginationIterator<Task>
Parameters
fileId
The ID of the file
fields
completion
Returns all of the tasks on the file
-
Get representations for a file.
Declaration
Parameters
fileId
The id of the file to retrieve representations for.
xRepHints
The representation to retrieve for the file. Can be set with format: [jpg?dimensions=32x32][png?dimensions=1024x1024].
completion
Returns an array of the specified representations.
-
Download a file to a specified folder.
Declaration
Swift
public func downloadFile( fileId: String, version: String? = nil, destinationURL: URL, progress: @escaping (Progress) -> Void = { _ in }, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
fileId
The ID of the file
version
Optional file version ID to download (defaults to the current version)
destinationURL
A URL for the location on device that we want to store the file once been donwloaded
progress
Shows the progress of the upload
completion
Returns an empty response or an error
-
Add file to favorites
Declaration
Swift
public func addFileToFavorites( fileId: String, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
fileId
The ID of the file
completion
Returns an empty response or an error
-
Add file to particular collection
Declaration
Swift
public func addFile( fileId: String, toCollection collectionId: String, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
fileId
The ID of the file
toCollection
The ID of the collection
completion
Returns an empty response or an error
-
Remove file from favorites
Declaration
Swift
public func removeFileFromFavorites( fileId: String, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
fileId
The ID of the file
completion
Returns an empty response or an error
-
Add file to particular collection
Declaration
Swift
public func removeFile( fileId: String, fromCollection collectionId: String, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
fileId
The ID of the file
fromCollection
The ID of the collection
completion
Returns an empty response or an error
-
Gets file with updated shared link
Declaration
Swift
public func getSharedLink( forFile fileId: String, completion: @escaping (Result<SharedLink, BoxError>) -> Void )
Parameters
fileId
The ID of the file
completion
Returns a standard SharedLink object or an error
-
Creates of updates shared link for a file
Declaration
Swift
public func setSharedLink( forFile fileId: String, stopSharingAt: Date? = nil, access: SharedLinkAccess? = nil, password: OptionalParameter<String>? = nil, canDownload: Bool? = nil, completion: @escaping (Result<SharedLink, BoxError>) -> Void )
Parameters
fileId
The ID of the file
stopSharingAt
The date-time that this link will become disabled. This field can only be set by users with paid accounts
access
The 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
password
The password required to access the shared link. Set to .empty to delete the password
canDownload
Whether the shared link allows downloads
completion
Returns a standard SharedLink object or an error
-
Removes shared link for a file
Declaration
Swift
public func deleteSharedLink( forFile fileId: String, completion: @escaping (Result<Void, BoxError>) -> Void )
Parameters
fileId
The ID of the file
completion
Returns an empty response or an error