FIRStorageReference

@interface FIRStorageReference : NSObject

FIRStorageReference represents a reference to a Google Cloud Storage object. Developers can upload and download objects, as well as get/set object metadata, and delete an object at the path. - see: https://cloud.google.com/storage/

  • The FIRStorage service object which created this reference.

    Declaration

    Swift

    var storage: FIRStorage { get }

    Objective-C

    @property (readonly, nonatomic) FIRStorage *_Nonnull storage;
  • The name of the Google Cloud Storage bucket associated with this reference, in gs://bucket/path/to/object.txt, the bucket would be: ‘bucket’

    Declaration

    Swift

    var bucket: String { get }

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull bucket;
  • The full path to this object, not including the Google Cloud Storage bucket. In gs://bucket/path/to/object.txt, the full path would be: ‘path/to/object.txt’

    Declaration

    Swift

    var fullPath: String { get }

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull fullPath;
  • The short name of the object associated with this reference, in gs://bucket/path/to/object.txt, the name of the object would be: ‘object.txt’

    Declaration

    Swift

    var name: String { get }

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull name;
  • Creates a new FIRStorageReference pointing to the root object. - returns: A new FIRStorageReference pointing to the root object.

    Declaration

    Swift

    func root() -> FIRStorageReference

    Objective-C

    - (nonnull FIRStorageReference *)root;

    Return Value

    A new FIRStorageReference pointing to the root object.

  • Creates a new FIRStorageReference pointing to the parent of the current reference or nil if this instance references the root location. For example: path = foo/bar/baz parent = foo/bar path = foo parent = (root) path = (root) parent = nil - returns: A new FIRStorageReference pointing to the parent of the current reference.

    Declaration

    Swift

    func parent() -> FIRStorageReference?

    Objective-C

    - (nullable FIRStorageReference *)parent;

    Return Value

    A new FIRStorageReference pointing to the parent of the current reference.

  • Creates a new FIRStorageReference pointing to a child object of the current reference. path = foo child = bar newPath = foo/bar path = foo/bar child = baz newPath = foo/bar/baz All leading and trailing slashes will be removed, and consecutive slashes will be compressed to single slashes. For example: child = /foo/bar newPath = foo/bar child = foo/bar/ newPath = foo/bar child = foo///bar newPath = foo/bar - parameter: path Path to append to the current path. - returns: A new FIRStorageReference pointing to a child location of the current reference.

    Declaration

    Swift

    func child(_ path: String) -> FIRStorageReference

    Objective-C

    - (nonnull FIRStorageReference *)child:(nonnull NSString *)path;

    Parameters

    path

    Path to append to the current path.

    Return Value

    A new FIRStorageReference pointing to a child location of the current reference.

  • Asynchronously uploads data to the currently specified FIRStorageReference, without additional metadata. This is not recommended for large files, and one should instead upload a file from disk. - parameter: uploadData The NSData to upload. - returns: An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

    Declaration

    Swift

    func put(_ uploadData: Data) -> FIRStorageUploadTask

    Objective-C

    - (nonnull FIRStorageUploadTask *)putData:(nonnull NSData *)uploadData;

    Parameters

    uploadData

    The NSData to upload.

    Return Value

    An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

  • Asynchronously uploads data to the currently specified FIRStorageReference. This is not recommended for large files, and one should instead upload a file from disk. - parameter: uploadData The NSData to upload. - parameter: metadata FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded. - returns: An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

    Declaration

    Swift

    func put(_ uploadData: Data, metadata: FIRStorageMetadata?) -> FIRStorageUploadTask

    Objective-C

    - (nonnull FIRStorageUploadTask *)putData:(nonnull NSData *)uploadData
                                     metadata:
                                         (nullable FIRStorageMetadata *)metadata;

    Parameters

    uploadData

    The NSData to upload.

    metadata

    FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded.

    Return Value

    An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

  • Asynchronously uploads data to the currently specified FIRStorageReference. This is not recommended for large files, and one should instead upload a file from disk. - parameter: uploadData The NSData to upload. - parameter: metadata FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded. - parameter: completion A completion block that either returns the object metadata on success, or an error on failure. - returns: An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

    Declaration

    Swift

    func put(_ uploadData: Data, metadata: FIRStorageMetadata?, completion: ((FIRStorageMetadata?, Error?) -> Void)? = nil) -> FIRStorageUploadTask

    Objective-C

    - (nonnull FIRStorageUploadTask *)
       putData:(nonnull NSData *)uploadData
      metadata:(nullable FIRStorageMetadata *)metadata
    completion:(nullable void (^)(FIRStorageMetadata *_Nullable,
                                  NSError *_Nullable))completion;

    Parameters

    uploadData

    The NSData to upload.

    metadata

    FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded.

    completion

    A completion block that either returns the object metadata on success, or an error on failure.

    Return Value

    An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

  • Asynchronously uploads a file to the currently specified FIRStorageReference, without additional metadata. - parameter: fileURL A URL representing the system file path of the object to be uploaded. - returns: An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

    Declaration

    Swift

    func putFile(_ fileURL: URL) -> FIRStorageUploadTask

    Objective-C

    - (nonnull FIRStorageUploadTask *)putFile:(nonnull NSURL *)fileURL;

    Parameters

    fileURL

    A URL representing the system file path of the object to be uploaded.

    Return Value

    An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

  • Asynchronously uploads a file to the currently specified FIRStorageReference. - parameter: fileURL A URL representing the system file path of the object to be uploaded. - parameter: metadata FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded. - returns: An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

    Declaration

    Swift

    func putFile(_ fileURL: URL, metadata: FIRStorageMetadata?) -> FIRStorageUploadTask

    Objective-C

    - (nonnull FIRStorageUploadTask *)putFile:(nonnull NSURL *)fileURL
                                     metadata:
                                         (nullable FIRStorageMetadata *)metadata;

    Parameters

    fileURL

    A URL representing the system file path of the object to be uploaded.

    metadata

    FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded.

    Return Value

    An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

  • Asynchronously uploads a file to the currently specified FIRStorageReference. - parameter: fileURL A URL representing the system file path of the object to be uploaded. - parameter: metadata FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded. - parameter: completion A completion block that either returns the object metadata on success, or an error on failure. - returns: An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

    Declaration

    Swift

    func putFile(_ fileURL: URL, metadata: FIRStorageMetadata?, completion: ((FIRStorageMetadata?, Error?) -> Void)? = nil) -> FIRStorageUploadTask

    Objective-C

    - (nonnull FIRStorageUploadTask *)
       putFile:(nonnull NSURL *)fileURL
      metadata:(nullable FIRStorageMetadata *)metadata
    completion:(nullable void (^)(FIRStorageMetadata *_Nullable,
                                  NSError *_Nullable))completion;

    Parameters

    fileURL

    A URL representing the system file path of the object to be uploaded.

    metadata

    FIRStorageMetadata containing additional information (MIME type, etc.) about the object being uploaded.

    completion

    A completion block that either returns the object metadata on success, or an error on failure.

    Return Value

    An instance of FIRStorageUploadTask, which can be used to monitor or manage the upload.

  • Asynchronously downloads the object at the FIRStorageReference to an NSData object in memory. An NSData of the provided max size will be allocated, so ensure that the device has enough free memory to complete the download. For downloading large files, writeToFile may be a better option. - parameter: size The maximum size in bytes to download. If the download exceeds this size the task will be cancelled and an error will be returned. - parameter: completion A completion block that either returns the object data on success, or an error on failure. - returns: An FIRStorageDownloadTask that can be used to monitor or manage the download.

    Declaration

    Swift

    func data(withMaxSize size: Int64, completion: @escaping (Data?, Error?) -> Void) -> FIRStorageDownloadTask

    Objective-C

    - (nonnull FIRStorageDownloadTask *)
    dataWithMaxSize:(int64_t)size
         completion:
             (nonnull void (^)(NSData *_Nullable, NSError *_Nullable))completion;

    Parameters

    size

    The maximum size in bytes to download. If the download exceeds this size the task will be cancelled and an error will be returned.

    completion

    A completion block that either returns the object data on success, or an error on failure.

    Return Value

    An FIRStorageDownloadTask that can be used to monitor or manage the download.

  • Asynchronously retrieves a long lived download URL with a revokable token. This can be used to share the file with others, but can be revoked by a developer in the Firebase Console if desired. - parameter: completion A completion block that either returns the URL on success, or an error on failure.

    Declaration

    Swift

    func downloadURL(completion: @escaping (URL?, Error?) -> Void)

    Objective-C

    - (void)downloadURLWithCompletion:
        (nonnull void (^)(NSURL *_Nullable, NSError *_Nullable))completion;

    Parameters

    completion

    A completion block that either returns the URL on success, or an error on failure.

  • Asynchronously downloads the object at the current path to a specified system filepath. - parameter: fileURL A file system URL representing the path the object should be downloaded to. - returns: An FIRStorageDownloadTask that can be used to monitor or manage the download.

    Declaration

    Swift

    func write(toFile fileURL: URL) -> FIRStorageDownloadTask

    Objective-C

    - (nonnull FIRStorageDownloadTask *)writeToFile:(nonnull NSURL *)fileURL;

    Parameters

    fileURL

    A file system URL representing the path the object should be downloaded to.

    Return Value

    An FIRStorageDownloadTask that can be used to monitor or manage the download.

  • Asynchronously downloads the object at the current path to a specified system filepath. - parameter: fileURL A file system URL representing the path the object should be downloaded to. - parameter: completion A completion block that fires when the file download completes. Returns an NSURL pointing to the file path of the downloaded file on success, or an error on failure. - returns: An FIRStorageDownloadTask that can be used to monitor or manage the download.

    Declaration

    Swift

    func write(toFile fileURL: URL, completion: ((URL?, Error?) -> Void)? = nil) -> FIRStorageDownloadTask

    Objective-C

    - (nonnull FIRStorageDownloadTask *)
    writeToFile:(nonnull NSURL *)fileURL
     completion:(nullable void (^)(NSURL *_Nullable, NSError *_Nullable))completion;

    Parameters

    fileURL

    A file system URL representing the path the object should be downloaded to.

    completion

    A completion block that fires when the file download completes. Returns an NSURL pointing to the file path of the downloaded file on success, or an error on failure.

    Return Value

    An FIRStorageDownloadTask that can be used to monitor or manage the download.

  • Retrieves metadata associated with an object at the current path. - parameter: completion A completion block which returns the object metadata on success, or an error on failure.

    Declaration

    Swift

    func metadata(completion: @escaping (FIRStorageMetadata?, Error?) -> Void)

    Objective-C

    - (void)metadataWithCompletion:(nonnull void (^)(FIRStorageMetadata *_Nullable,
                                                     NSError *_Nullable))completion;

    Parameters

    completion

    A completion block which returns the object metadata on success, or an error on failure.

  • Updates the metadata associated with an object at the current path. - parameter: metadata An FIRStorageMetadata object with the metadata to update. - parameter: completion A completion block which returns the FIRStorageMetadata on success, or an error on failure.

    Declaration

    Swift

    func update(_ metadata: FIRStorageMetadata, completion: ((FIRStorageMetadata?, Error?) -> Void)? = nil)

    Objective-C

    - (void)updateMetadata:(nonnull FIRStorageMetadata *)metadata
                completion:(nullable void (^)(FIRStorageMetadata *_Nullable,
                                              NSError *_Nullable))completion;

    Parameters

    metadata

    An FIRStorageMetadata object with the metadata to update.

    completion

    A completion block which returns the FIRStorageMetadata on success, or an error on failure.

  • Deletes the object at the current path. - parameter: completion A completion block which returns nil on success, or an error on failure.

    Declaration

    Swift

    func delete(completion: ((Error?) -> Void)? = nil)

    Objective-C

    - (void)deleteWithCompletion:(nullable void (^)(NSError *_Nullable))completion;

    Parameters

    completion

    A completion block which returns nil on success, or an error on failure.