PFFile

@interface PFFile : NSObject

PFFile representes a file of binary data stored on the Parse servers. This can be a image, video, or anything else that an application needs to reference in a non-relational way.


  • Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Creates a file with given data. A name will be assigned to it by the server.

    Declaration

    Objective-C

    + (nullable instancetype)fileWithData:(nonnull NSData *)data;

    Parameters

    data

    The contents of the new PFFile.

    Return Value

    A new PFFile.

  • Creates a file with given data and name.

    Declaration

    Objective-C

    + (nullable instancetype)fileWithName:(nullable NSString *)name
                                     data:(nonnull NSData *)data;

    Parameters

    name

    The name of the new PFFile. The file name must begin with and alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes.

    data

    The contents of the new PFFile.

    Return Value

    A new PFFile object.

  • Creates a file with the contents of another file.

    Warning

    This method raises an exception if the file at path is not accessible or if there is not enough disk space left.

    Declaration

    Objective-C

    + (nullable instancetype)fileWithName:(nullable NSString *)name
                           contentsAtPath:(nonnull NSString *)path;

    Parameters

    name

    The name of the new PFFile. The file name must begin with and alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes.

    path

    The path to the file that will be uploaded to Parse.

    Return Value

    A new PFFile instance.

  • Creates a file with the contents of another file.

    Declaration

    Objective-C

    + (nullable instancetype)fileWithName:(nullable NSString *)name
                           contentsAtPath:(nonnull NSString *)path
                                    error:(NSError *_Nullable *_Nullable)error;

    Parameters

    name

    The name of the new PFFile. The file name must begin with and alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes.

    path

    The path to the file that will be uploaded to Parse.

    error

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

    Return Value

    A new PFFile instance or nil if the error occured.

  • Creates a file with given data, name and content type.

    Warning

    This method raises an exception if the data supplied is not accessible or could not be saved.

    Declaration

    Objective-C

    + (nullable instancetype)fileWithName:(nullable NSString *)name
                                     data:(nonnull NSData *)data
                              contentType:(nullable NSString *)contentType;

    Parameters

    name
       The name of the new `PFFile`. The file name must begin with and alphanumeric character,
    

    and consist of alphanumeric characters, periods, spaces, underscores, or dashes.

    data

    The contents of the new PFFile.

    contentType

    Represents MIME type of the data.

    Return Value

    A new PFFile instance.

  • Creates a file with given data, name and content type.

    Declaration

    Objective-C

    + (nullable instancetype)fileWithName:(nullable NSString *)name
                                     data:(nonnull NSData *)data
                              contentType:(nullable NSString *)contentType
                                    error:(NSError *_Nullable *_Nullable)error;

    Parameters

    name
       The name of the new `PFFile`. The file name must begin with and alphanumeric character,
    

    and consist of alphanumeric characters, periods, spaces, underscores, or dashes.

    data

    The contents of the new PFFile.

    contentType

    Represents MIME type of the data.

    error

    On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

    Return Value

    A new PFFile instance or nil if the error occured.

  • Creates a file with given data and content type.

    Declaration

    Objective-C

    + (nonnull instancetype)fileWithData:(nonnull NSData *)data
                             contentType:(nullable NSString *)contentType;

    Parameters

    data

    The contents of the new PFFile.

    contentType

    Represents MIME type of the data.

    Return Value

    A new PFFile object.

  • 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

    Objective-C

    @property (readonly, copy, nonatomic) NSString *_Nonnull name;
  • url

    The url of the file.

    Declaration

    Objective-C

    @property (readonly, copy, nonatomic, nullable) NSString *url;
  • Whether the file has been uploaded for the first time.

    Declaration

    Objective-C

    @property (readonly, getter=isDirty, assign, nonatomic) BOOL dirty;
  • Saves the file asynchronously.

    Declaration

    Objective-C

    - (id)saveInBackground;

    Return Value

    The task, that encapsulates the work being done.

  • Saves the file asynchronously

    Declaration

    Objective-C

    - (id)saveInBackgroundWithProgressBlock:(nullable PFProgressBlock)progressBlock;

    Parameters

    progressBlock

    The block should have the following argument signature: ^(int percentDone)

    Return Value

    The task, that encapsulates the work being done.

  • Saves the file asynchronously and executes the given block.

    Declaration

    Objective-C

    - (void)saveInBackgroundWithBlock:(nullable PFBooleanResultBlock)block;

    Parameters

    block

    The block should have the following argument signature: ^(BOOL succeeded, NSError *error).

  • Saves the file asynchronously and executes the given block.

    This method will execute the progressBlock periodically with the percent progress. progressBlock will get called with 100 before resultBlock is called.

    Declaration

    Objective-C

    - (void)saveInBackgroundWithBlock:(nullable PFBooleanResultBlock)block
                        progressBlock:(nullable PFProgressBlock)progressBlock;

    Parameters

    block

    The block should have the following argument signature: ^(BOOL succeeded, NSError *error)

    progressBlock

    The block should have the following argument signature: ^(int percentDone)

  • Whether the data is available in memory or needs to be downloaded.

    Declaration

    Objective-C

    @property (readonly, getter=isDataAvailable, assign, nonatomic)
        BOOL dataAvailable;
  • This method is like -getData but it fetches asynchronously to avoid blocking the current thread.

    See

    getData

    Declaration

    Objective-C

    - (id)getDataInBackground;

    Return Value

    The task, that encapsulates the work being done.

  • This method is like -getData but it fetches asynchronously to avoid blocking the current thread.

    This can help applications with many large files avoid memory warnings.

    See

    getData

    Declaration

    Objective-C

    - (id)getDataInBackgroundWithProgressBlock:
            (nullable PFProgressBlock)progressBlock;

    Parameters

    progressBlock

    The block should have the following argument signature: ^(int percentDone)

    Return Value

    The task, that encapsulates the work being done.

  • This method is like -getDataInBackground but avoids ever holding the entire PFFile contents in memory at once.

    This can help applications with many large files avoid memory warnings.

    Declaration

    Objective-C

    - (id)getDataStreamInBackground;

    Return Value

    The task, that encapsulates the work being done.

  • This method is like -getDataStreamInBackground, but yields a live-updating stream.

    Instead of -getDataStream, which yields a stream that can be read from only after the request has completed, this method gives you a stream directly written to by the HTTP session. As this stream is not pre-buffered, it is strongly advised to use the NSStreamDelegate methods, in combination with a run loop, to consume the data in the stream, to do proper async file downloading.

    Note

    You MUST open this stream before reading from it.

    Note

    Do NOT call waitUntilFinished on this task from the main thread. It may result in a deadlock.

    Declaration

    Objective-C

    - (id)getDataDownloadStreamInBackground;

    Return Value

    A task that produces a live stream that is being written to with the data from the server.

  • This method is like -getDataInBackground but avoids ever holding the entire PFFile contents in memory at once.

    This can help applications with many large files avoid memory warnings. - parameter: progressBlock The block should have the following argument signature: ^(int percentDone)

    Declaration

    Objective-C

    - (id)getDataStreamInBackgroundWithProgressBlock:
            (nullable PFProgressBlock)progressBlock;

    Parameters

    progressBlock

    The block should have the following argument signature: ^(int percentDone)

    Return Value

    The task, that encapsulates the work being done.

  • This method is like -getDataStreamInBackgroundWithProgressBlock:, but yields a live-updating stream.

    Instead of -getDataStream, which yields a stream that can be read from only after the request has completed, this method gives you a stream directly written to by the HTTP session. As this stream is not pre-buffered, it is strongly advised to use the NSStreamDelegate methods, in combination with a run loop, to consume the data in the stream, to do proper async file downloading.

    Note

    You MUST open this stream before reading from it.

    Note

    Do NOT call waitUntilFinished on this task from the main thread. It may result in a deadlock.

    Declaration

    Objective-C

    - (id)getDataDownloadStreamInBackgroundWithProgressBlock:
            (nullable PFProgressBlock)progressBlock;

    Parameters

    progressBlock

    The block should have the following argument signature: ^(int percentDone)

    Return Value

    A task that produces a live stream that is being written to with the data from the server.

  • Asynchronously gets the data from cache if available or fetches its contents from the network.

    Declaration

    Objective-C

    - (void)getDataInBackgroundWithBlock:(nullable PFDataResultBlock)block;

    Parameters

    block

    The block should have the following argument signature: ^(NSData *result, NSError *error)

  • This method is like -getDataInBackgroundWithBlock: but avoids ever holding the entire PFFile contents in memory at once.

    This can help applications with many large files avoid memory warnings.

    Declaration

    Objective-C

    - (void)getDataStreamInBackgroundWithBlock:
            (nullable PFDataStreamResultBlock)block;

    Parameters

    block

    The block should have the following argument signature: (NSInputStream *result, NSError *error)

  • Asynchronously gets the data from cache if available or fetches its contents from the network.

    This method will execute the progressBlock periodically with the percent progress. progressBlock will get called with 100 before resultBlock is called.

    Declaration

    Objective-C

    - (void)getDataInBackgroundWithBlock:(nullable PFDataResultBlock)resultBlock
                           progressBlock:(nullable PFProgressBlock)progressBlock;

    Parameters

    resultBlock

    The block should have the following argument signature: ^(NSData *result, NSError *error)

    progressBlock

    The block should have the following argument signature: ^(int percentDone)

  • This method is like -getDataInBackgroundWithBlock:progressBlock: but avoids ever holding the entire PFFile contents in memory at once.

    This can help applications with many large files avoid memory warnings.

    Declaration

    Objective-C

    - (void)getDataStreamInBackgroundWithBlock:
                (nullable PFDataStreamResultBlock)resultBlock
                                 progressBlock:
                                     (nullable PFProgressBlock)progressBlock;

    Parameters

    resultBlock

    The block should have the following argument signature: ^(NSInputStream *result, NSError *error).

    progressBlock

    The block should have the following argument signature: ^(int percentDone).

  • Asynchronously gets the file path for file from cache if available or fetches its contents from the network.

    Note

    The file path may change between versions of SDK.

    Note

    If you overwrite the contents of the file at returned path it will persist those change until the file cache is cleared.

    Declaration

    Objective-C

    - (id)getFilePathInBackground;

    Return Value

    The task, with the result set to NSString representation of a file path.

  • Asynchronously gets the file path for file from cache if available or fetches its contents from the network.

    Note

    The file path may change between versions of SDK.

    Note

    If you overwrite the contents of the file at returned path it will persist those change until the file cache is cleared.

    Declaration

    Objective-C

    - (id)getFilePathInBackgroundWithProgressBlock:
            (nullable PFProgressBlock)progressBlock;

    Parameters

    progressBlock

    The block should have the following argument signature: ^(int percentDone).

    Return Value

    The task, with the result set to NSString representation of a file path.

  • Asynchronously gets the file path for file from cache if available or fetches its contents from the network.

    Note

    The file path may change between versions of SDK.

    Note

    If you overwrite the contents of the file at returned path it will persist those change until the file cache is cleared.

    Declaration

    Objective-C

    - (void)getFilePathInBackgroundWithBlock:(nullable PFFilePathResultBlock)block;

    Parameters

    block

    The block should have the following argument signature: ^(NSString *filePath, NSError *error).

  • Asynchronously gets the file path for file from cache if available or fetches its contents from the network.

    Note

    The file path may change between versions of SDK.

    Note

    If you overwrite the contents of the file at returned path it will persist those change until the file cache is cleared.

    Declaration

    Objective-C

    - (void)getFilePathInBackgroundWithBlock:(nullable PFFilePathResultBlock)block
                               progressBlock:
                                   (nullable PFProgressBlock)progressBlock;

    Parameters

    block

    The block should have the following argument signature: ^(NSString *filePath, NSError *error).

    progressBlock

    The block should have the following argument signature: ^(int percentDone).

  • Cancels the current request (upload or download of file).

    Declaration

    Objective-C

    - (void)cancel;