ParseFile
public struct ParseFile : Fileable, Savable, Fetchable, Deletable, Hashable
extension ParseFile: CustomDebugStringConvertible
extension ParseFile: CustomStringConvertible
A ParseFile
object representes a file of binary data stored on the Parse server.
This can be a image, video, or anything else that an application needs to reference in a non-relational way.
-
Declaration
Swift
public var id: UUID
-
The name of the file. Before the file is saved, this is the filename given by the user. After the file is saved, that name gets prefixed with a unique identifier.
Declaration
Swift
public internal(set) var name: String { get }
-
The Parse Server url of the file.
Declaration
Swift
public internal(set) var url: URL? { get }
-
The local file path.
Declaration
Swift
public var localURL: URL?
-
The link to the file online that should be fetched before uploading to the Parse Server.
Declaration
Swift
public var cloudURL: URL?
-
The contents of the file.
Declaration
Swift
public var data: Data?
-
The Content-Type header to use for the file.
Declaration
Swift
public var mimeType: String?
-
Key value pairs to be stored with the file object.
Declaration
Swift
public var metadata: [String : String]?
-
Key value pairs to be stored with the file object.
Declaration
Swift
public var tags: [String : String]?
-
A set of header options sent to the server.
Declaration
Swift
public var options: API.Options
-
Creates a file with given data and name.
Note
metadata
andtags
is file adapter specific and not supported by all file adapters. For more, see details on the S3 adapterDeclaration
Swift
public init(name: String = "file", data: Data, mimeType: String? = nil, metadata: [String: String]? = nil, tags: [String: String]? = nil, options: API.Options = [])
Parameters
name
The name of the new
ParseFile
. The file name must begin with and alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes. The default value is “file”.data
The contents of the new
ParseFile
.mimeType
Specify the Content-Type header to use for the file, for example “application/pdf”. The default is nil. If no value is specified the file type will be inferred from the file extention of
name
.metadata
Optional key value pairs to be stored with file object
tags
Optional key value pairs to be stored with file object
-
Creates a file from a local file path and name.
Note
metadata
andtags
is file adapter specific and not supported by all file adapters. For more, see details on the S3 adapter.Declaration
Swift
public init(name: String = "file", localURL: URL, metadata: [String: String]? = nil, tags: [String: String]? = nil, options: API.Options = [])
Parameters
name
The name of the new
ParseFile
. The file name must begin with and alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes. The default value is “file”.localURL
The local file path of the
ParseFile
.mimeType
Specify the Content-Type header to use for the file, for example “application/pdf”. The default is nil. If no value is specified the file type will be inferred from the file extention of
name
.metadata
Optional key value pairs to be stored with file object.
tags
Optional key value pairs to be stored with file object.
-
Creates a file from a link online and name.
Note
metadata
andtags
is file adapter specific and not supported by all file adapters. For more, see details on the S3 adapter.Declaration
Swift
public init(name: String = "file", cloudURL: URL, metadata: [String: String]? = nil, tags: [String: String]? = nil, options: API.Options = [])
Parameters
name
The name of the new
ParseFile
. The file name must begin with and alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes. The default value is “file”.cloudURL
The online link of the
ParseFile
.mimeType
Specify the Content-Type header to use for the file, for example “application/pdf”. The default is nil. If no value is specified the file type will be inferred from the file extention of
name
.metadata
Optional key value pairs to be stored with file object.
tags
Optional key value pairs to be stored with file object.
-
fetch(options:
Asynchronous) Fetches a file with given url asynchronously.
Throws
An error of typeParseError
.Note
The default cache policy for this method is.reloadIgnoringLocalCacheData
. If a developer desires a different policy, it should be inserted inoptions
.Declaration
Swift
func fetch(options: API.Options = []) async throws -> ParseFile
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A fetched
ParseFile
. -
fetch(options:
Asynchronousprogress: ) Fetches a file with given url asynchronously.
Throws
An error of typeParseError
.Note
The default cache policy for this method is.reloadIgnoringLocalCacheData
. If a developer desires a different policy, it should be inserted inoptions
.Declaration
Swift
func fetch(options: API.Options = [], progress: @escaping ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)) async throws -> Self
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.Return Value
A fetched
ParseFile
. -
save(options:
Asynchronous) Creates a file with given data asynchronously and executes the given callback block. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved.
Throws
An error of typeParseError
.Declaration
Swift
func save(options: API.Options = []) async throws -> ParseFile
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A saved
ParseFile
. -
save(options:
Asynchronousprogress: ) Creates a file with given data asynchronously and executes the given callback block. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved.
Throws
An error of typeParseError
.Declaration
Swift
func save(options: API.Options = [], progress: ((URLSessionTask, Int64, Int64, Int64) -> Void)? = nil) async throws -> Self
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.Return Value
A ParsFile.
-
delete(options:
Asynchronous) Deletes the file from the Parse Server.
Requires
.useMasterKey
has to be available.Throws
An error of typeParseError
.Declaration
Swift
func delete(options: API.Options = []) async throws
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
-
Fetches a file with given url synchronously. Publishes when complete.
Note
The default cache policy for this method is.reloadIgnoringLocalCacheData
. If a developer desires a different policy, it should be inserted inoptions
.Declaration
Swift
func fetchPublisher(options: API.Options = []) -> Future<`Self`, ParseError>
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A publisher that eventually produces a single value and then finishes or fails.
-
Fetches a file with given url synchronously. Publishes when complete.
Note
The default cache policy for this method is.reloadIgnoringLocalCacheData
. If a developer desires a different policy, it should be inserted inoptions
.Declaration
Swift
func fetchPublisher(options: API.Options = [], progress: @escaping ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)) -> Future<Self, ParseError>
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.Return Value
A publisher that eventually produces a single value and then finishes or fails.
-
Creates a file with given data asynchronously and executes the given callback block. Publishes when complete. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved.
Declaration
Swift
func savePublisher(options: API.Options = []) -> Future<`Self`, ParseError>
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A publisher that eventually produces a single value and then finishes or fails.
-
Creates a file with given data asynchronously and executes the given callback block. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved. Publishes when complete.
Declaration
Swift
func savePublisher(options: API.Options = [], progress: ((URLSessionTask, Int64, Int64, Int64) -> Void)? = nil) -> Future<Self, ParseError>
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.Return Value
A publisher that eventually produces a single value and then finishes or fails.
-
Deletes the file from the Parse Server. Publishes when complete.
Requires
.useMasterKey
has to be available.Declaration
Swift
func deletePublisher(options: API.Options = []) -> Future<Void, ParseError>
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A publisher that eventually produces a single value and then finishes or fails.
-
Declaration
Swift
public init(from decoder: Decoder) throws
-
Deletes the file from the Parse cloud.
Requires
.useMasterKey
has to be available.Throws
AParseError
if there was an issue deleting the file. Otherwise it was successful.Note
The default cache policy for this method is.reloadIgnoringLocalCacheData
. If a developer desires a different policy, it should be inserted inoptions
.Declaration
Swift
public func delete(options: API.Options, callbackQueue: DispatchQueue) throws
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after synchronous completion.
-
Deletes the file from the Parse cloud.
Requires
.useMasterKey
has to be available.Throws
AParseError
if there was an issue deleting the file. Otherwise it was successful.Declaration
Swift
public func delete(options: API.Options) throws
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
-
Deletes the file from the Parse cloud. Completes with
nil
if successful.Requires
.useMasterKey
has to be available.Note
The default cache policy for this method is.reloadIgnoringLocalCacheData
. If a developer desires a different policy, it should be inserted inoptions
.Declaration
Swift
public func delete(options: API.Options, callbackQueue: DispatchQueue = .main, completion: @escaping (Result<Void, ParseError>) -> Void)
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after completion. Default value of .main.
completion
A block that will be called when file deletes or fails. It should have the following argument signature:
(Result<Void, ParseError>)
.
-
Creates a file with given stream synchronously. A name will be assigned to it by the server.
Checking progress*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.fetch(stream: InputStream(fileAtPath: URL("parse.org")!) { (_, _, totalWritten, totalExpected) in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 print(currentProgess) }
Cancelling*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.fetch(stream: InputStream(fileAtPath: URL("parse.org")!){ (task, _, totalWritten, totalExpected) in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 //Cancel when data exceeds 10% if currentProgess > 10 { task.cancel() print("task has been cancelled") } print(currentProgess) }
Declaration
Swift
public func save(options: API.Options = [], stream: InputStream, callbackQueue: DispatchQueue = .main, progress: ((URLSessionTask, Int64, Int64, Int64) -> Void)? = nil) throws
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.stream
An input file stream.
callbackQueue
The queue to return to after synchronous completion. Default value of .main.
Return Value
A saved
ParseFile
. -
Creates a file with given data synchronously. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved.
Declaration
Swift
public func save(options: API.Options = []) throws -> ParseFile
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A saved
ParseFile
. -
Creates a file with given data synchronously. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved.
Checking progress*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.save { (_, _, totalWritten, totalExpected) in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 print(currentProgess) }
Cancelling*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.save { (task, _, totalWritten, totalExpected) in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 //Cancel when data exceeds 10% if currentProgess > 10 { task.cancel() print("task has been cancelled") } print(currentProgess) }
Declaration
Swift
public func save(options: API.Options = [], callbackQueue: DispatchQueue = .main, progress: ((URLSessionTask, Int64, Int64, Int64) -> Void)?) throws -> ParseFile
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after synchronous completion. Defailts to .main.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.Return Value
A saved
ParseFile
. -
Creates a file with given data asynchronously and executes the given callback block. A name will be assigned to it by the server. If the file hasn’t been downloaded, it will automatically be downloaded before saved.
Checking progress*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.save { (_, _, totalWritten, totalExpected) in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 print(currentProgess) }
Cancelling*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.save(progress: {(task, _, totalWritten, totalExpected)-> Void in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 //Cancel when data exceeds 10% if currentProgess > 10 { task.cancel() print("task has been cancelled") } print(currentProgess) }) { result in ... })
Declaration
Swift
public func save(options: API.Options = [], callbackQueue: DispatchQueue = .main, progress: ((URLSessionTask, Int64, Int64, Int64) -> Void)? = nil, completion: @escaping (Result<Self, ParseError>) -> Void)
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after completion. Default value of .main.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.completion
A block that will be called when file saves or fails. It should have the following argument signature:
(Result<Self, ParseError>)
.
-
Fetches a file with given url synchronously.
Declaration
Swift
public func fetch(options: API.Options = [], stream: InputStream, callbackQueue: DispatchQueue = .main) throws
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
stream
An input file stream.
callbackQueue
The queue to return to after synchronous completion. Default value of .main.
Return Value
A saved
ParseFile
. -
Fetches a file with given url synchronously.
Declaration
Swift
public func fetch(includeKeys: [String]? = nil, options: API.Options = [], callbackQueue: DispatchQueue) throws -> ParseFile
Parameters
includeKeys
Currently not used for
ParseFile
.options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after synchronous completion.
Return Value
A saved
ParseFile
. -
Fetches a file with given url synchronously.
Declaration
Swift
public func fetch(includeKeys: [String]? = nil, options: API.Options = []) throws -> ParseFile
Parameters
includeKeys
Currently not used for
ParseFile
.options
A set of header options sent to the server. Defaults to an empty set.
Return Value
A saved
ParseFile
. -
Fetches a file with given url synchronously.
Checking progress*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.fetch { (_, _, totalDownloaded, totalExpected) in let currentProgess = Double(totalWritten)/Double(totalExpected) * 100 print(currentProgess) }
Cancelling*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.fetch { (task, _, totalDownloaded, totalExpected) in let currentProgess = Double(totalDownloaded)/Double(totalExpected) * 100 //Cancel when data exceeds 10% if currentProgess > 10 { task.cancel() print("task has been cancelled") } print(currentProgess) }
Declaration
Swift
public func fetch(options: API.Options = [], callbackQueue: DispatchQueue = .main, progress: @escaping ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)) throws -> ParseFile
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after synchronous completion. Defaults to .main.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.Return Value
A saved
ParseFile
. -
Fetches a file with given url asynchronously.
Checking progress*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.fetch { (_, _, totalDownloaded, totalExpected) in let currentProgess = Double(totalDownloaded)/Double(totalExpected) * 100 print(currentProgess) }
Cancelling*
guard let parseFileURL = URL(string: "https://parseplatform.org/img/logo.svg") else { return } let parseFile = ParseFile(name: "logo.svg", cloudURL: parseFileURL) let fetchedFile = try parseFile.fetch(progress: {(task, _, totalDownloaded, totalExpected)-> Void in let currentProgess = Double(totalDownloaded)/Double(totalExpected) * 100 //Cancel when data exceeds 10% if currentProgess > 10 { task.cancel() print("task has been cancelled") } print(currentProgess) }) { result in ... }
Declaration
Swift
public func fetch(options: API.Options = [], callbackQueue: DispatchQueue = .main, progress: ((URLSessionDownloadTask, Int64, Int64, Int64) -> Void)? = nil, completion: @escaping (Result<Self, ParseError>) -> Void)
Parameters
options
A set of header options sent to the server. Defaults to an empty set.
callbackQueue
The queue to return to after completion. Default value of .main.
progress
A block that will be called when file updates it’s progress. It should have the following argument signature:
(task: URLSessionDownloadTask, bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64)
.completion
A block that will be called when file fetches or fails. It should have the following argument signature:
(Result<Self, ParseError>)
.
-
Declaration
Swift
public var debugDescription: String { get }
-
Declaration
Swift
public var description: String { get }