Firebase.Storage.StorageReference

Represents a reference to a Google CloudStorage object.

Summary

Represents a reference to a Google CloudStorage object. Developers can upload and download objects, get/set object metadata, and delete an object at a specified path. (seeGoogle Cloud Storage)

Properties

Bucket
string
Return the Google CloudStorage bucket that holds this object.
Name
string
Returns the short name of this object.
Parent
Returns a new instance ofStorageReference pointing to the parent location or null if this instance references the root location.
Path
string
Returns the full path to this object, not including the Google CloudStorage bucket.
Root
Returns a new instance ofStorageReference pointing to the root location.
Storage
Returns theFirebaseStorage service which created this reference.

Public functions

Child(string pathString)
Returns a new instance ofStorageReference pointing to a child location of the current reference.
DeleteAsync()
Task
Deletes the object at thisStorageReference
Equals(object other)
override bool
Compares two storage reference URIs.
GetBytesAsync(long maxDownloadSizeBytes)
Task< byte[]>
Downloads the object from thisStorageReference A byte array will be allocated large enough to hold the entire file in memory.
GetBytesAsync(long maxDownloadSizeBytes, IProgress<DownloadState > progressHandler, CancellationToken cancelToken)
Task< byte[]>
Downloads the object from thisStorageReference A byte array will be allocated large enough to hold the entire file in memory.
GetDownloadUrlAsync()
Task< Uri >
Retrieves a long lived download URL with a revokable token.
GetFileAsync(string destinationFilePath, IProgress<DownloadState > progressHandler, CancellationToken cancelToken)
Task
Downloads the object at thisStorageReference to a specified system filepath.
GetHashCode()
override int
Create a hash of the URI string used by this reference.
GetMetadataAsync()
Retrieves metadata associated with an object at thisStorageReference
GetStreamAsync()
Task< Stream >
Downloads the object at thisStorageReference via a Stream The resulting InputStream should be not be accessed on the main thread because calling into it may block the calling thread.
GetStreamAsync(Action< Stream > streamProcessor, IProgress<DownloadState > progressHandler, CancellationToken cancelToken)
Task
Downloads the object at thisStorageReference via a Stream
PutBytesAsync(byte[] bytes,MetadataChange customMetadata, IProgress<UploadState > progressHandler, CancellationToken cancelToken, Uri previousSessionUri)
Uploads byte data to thisStorageReference This is not recommended for large files.
PutFileAsync(string filePath,MetadataChange customMetadata, IProgress<UploadState > progressHandler, CancellationToken cancelToken, Uri previousSessionUri)
Uploads from a content URI to thisStorageReference
PutStreamAsync(Stream stream,MetadataChange customMetadata, IProgress<UploadState > progressHandler, CancellationToken cancelToken, Uri previousSessionUri)
Uploads a stream of data to thisStorageReference The stream will remain open at the end of the upload.
ToString()
override string
Returns
This object in URI form, which can then be shared and passed intoFirebaseStorage.GetReferenceFromUrl
UpdateMetadataAsync(MetadataChange metadata)
Updates the metadata associated with thisStorageReference

Properties

Bucket

stringBucket

Return the Google CloudStorage bucket that holds this object.

Details
Returns
the bucket.

Name

stringName

Returns the short name of this object.

Details
Returns
the name.

Parent

StorageReferenceParent

Returns a new instance ofStorageReference pointing to the parent location or null if this instance references the root location.

For example:

path=foo/bar/bazparent=foo/barpath=fooparent=(root)path=(root)parent=(null)

Details
Returns

Path

stringPath

Returns the full path to this object, not including the Google CloudStorage bucket.

Details
Returns
the path.

Root

StorageReferenceRoot

Returns a new instance ofStorageReference pointing to the root location.

Details
Returns

Storage

FirebaseStorageStorage

Returns theFirebaseStorage service which created this reference.

Details
Returns
TheFirebaseStorage service.

Public functions

Child

StorageReferenceChild(stringpathString)

Returns a new instance ofStorageReference pointing to a child location of the current reference.

All leading and trailing slashes will be removed, and consecutive slashes will be compressed to single slashes. For example:

child=/foo/barpath=foo/barchild=foo/bar/path=foo/barchild=foo///bar    path = foo/bar

Details
Parameters
pathString
The relative path from this reference.
Returns

DeleteAsync

TaskDeleteAsync()

Deletes the object at thisStorageReference

Details
Returns
A Task which can be used to monitor the operation and obtain the result.

Equals

overrideboolEquals(objectother)

Compares two storage reference URIs.

Details
Returns
true if two references point to the same path, false otherwise.

GetBytesAsync

Task<byte[]>GetBytesAsync(longmaxDownloadSizeBytes)

Downloads the object from thisStorageReference A byte array will be allocated large enough to hold the entire file in memory.

Therefore, using this method will impact memory usage of your process. If you are downloading many large files,GetStream(StreamDownloadTask.StreamProcessor)

may be a better option.

Details
Parameters
maxDownloadSizeBytes
The maximum allowed size in bytes that will be allocated. Set this parameter to prevent out of memory conditions from occurring. If the download exceeds this limit, the task will fail and an System.IndexOutOfRangeException will be returned.
Returns
A Task which can be used to monitor the operation and obtain the result.

GetBytesAsync

Task<byte[]>GetBytesAsync(longmaxDownloadSizeBytes,IProgress<DownloadState>progressHandler,CancellationTokencancelToken)

Downloads the object from thisStorageReference A byte array will be allocated large enough to hold the entire file in memory.

Therefore, using this method will impact memory usage of your process. If you are downloading many large files,GetStream(StreamDownloadTask.StreamProcessor)

may be a better option.

Details
Parameters
maxDownloadSizeBytes
The maximum allowed size in bytes that will be allocated. Set this parameter to prevent out of memory conditions from occurring. If the download exceeds this limit, the task will fail and an System.IndexOutOfRangeException will be returned.
progressHandler
usually an instance of StorageProgress that will receive periodic updates during the operation. This value can be null.
cancelToken
A CancellationToken to control the operation and possibly later cancel it. This value may be CancellationToken.None to indicate no value.
Returns
A Task which can be used to monitor the operation and obtain the result.

GetDownloadUrlAsync

Task<Uri>GetDownloadUrlAsync()

Retrieves a long lived download URL with a revokable token.

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 theFirebase Console if desired.

Details
Returns
A Task which can be used to monitor the operation and obtain the result.

GetFileAsync

TaskGetFileAsync(stringdestinationFilePath,IProgress<DownloadState>progressHandler,CancellationTokencancelToken)

Downloads the object at thisStorageReference to a specified system filepath.

Details
Parameters
destinationFilePath
A file system URI representing the path the object should be downloaded to.
progressHandler
usually an instance of StorageProgress that will receive periodic updates during the operation. This value can be null.
cancelToken
A CancellationToken to control the operation and possibly later cancel it. This value may be CancellationToken.None to indicate no value.
Returns
A Task which can be used to monitor the operation and obtain the result.

GetHashCode

overrideintGetHashCode()

Create a hash of the URI string used by this reference.

Details
Returns
Hash of this reference's URI.

GetMetadataAsync

Task<StorageMetadata>GetMetadataAsync()

Retrieves metadata associated with an object at thisStorageReference

Details
Returns
A Task which can be used to monitor the operation and obtain the result.

GetStreamAsync

Task<Stream>GetStreamAsync()

Downloads the object at thisStorageReference via a Stream The resulting InputStream should be not be accessed on the main thread because calling into it may block the calling thread.

Details
Returns
A Task which can be used to monitor the operation.

GetStreamAsync

TaskGetStreamAsync(Action<Stream>streamProcessor,IProgress<DownloadState>progressHandler,CancellationTokencancelToken)

Downloads the object at thisStorageReference via a Stream

Details
Parameters
streamProcessor
A delegate that is responsible for reading data from the Stream The delegate is called on a background thread and exceptions thrown from this object will be returned as a failure to the Task
progressHandler
usually an instance of StorageProgress that will receive periodic updates during the operation. This value can be null.
cancelToken
A CancellationToken to control the operation and possibly later cancel it. This value may be CancellationToken.None to indicate no value.
Returns
A Task which can be used to monitor the operation and obtain the result.

PutBytesAsync

Task<StorageMetadata>PutBytesAsync(byte[]bytes,MetadataChangecustomMetadata,IProgress<UploadState>progressHandler,CancellationTokencancelToken,UripreviousSessionUri)

Uploads byte data to thisStorageReference This is not recommended for large files.

Instead upload a file viaPutFile

or a Stream viaPutStream

Details
Parameters
bytes
The byte[] to upload.
customMetadata
MetadataChange containing additional information (MIME type, etc.) about the object being uploaded.
progressHandler
usually an instance of StorageProgress that will receive periodic updates during the operation. This value can be null.
cancelToken
A CancellationToken to control the operation and possibly later cancel it. This value may be CancellationToken.None to indicate no value.
previousSessionUri
A Uri previously obtained byUploadState.UploadSessionUri that can be used to resume a previously interrupted upload.
Returns
A Task which can be used to monitor the upload.

PutFileAsync

Task<StorageMetadata>PutFileAsync(stringfilePath,MetadataChangecustomMetadata,IProgress<UploadState>progressHandler,CancellationTokencancelToken,UripreviousSessionUri)

Uploads from a content URI to thisStorageReference

Details
Parameters
filePath
The source of the upload. This should be a file system URI representing the path the object should be uploaded from.
customMetadata
MetadataChange containing additional information (MIME type, etc.) about the object being uploaded.
progressHandler
usually an instance of StorageProgress that will receive periodic updates during the operation. This value can be null.
cancelToken
A CancellationToken to control the operation and possibly later cancel it. This value may be CancellationToken.None to indicate no value.
previousSessionUri
A Uri previously obtained byUploadState.UploadSessionUri that can be used to resume a previously interrupted upload.
Returns
A Task which can be used to monitor the upload.

PutStreamAsync

Task<StorageMetadata>PutStreamAsync(Streamstream,MetadataChangecustomMetadata,IProgress<UploadState>progressHandler,CancellationTokencancelToken,UripreviousSessionUri)

Uploads a stream of data to thisStorageReference The stream will remain open at the end of the upload.

Details
Parameters
stream
The Stream to upload.
customMetadata
MetadataChange containing additional information (MIME type, etc.) about the object being uploaded.
progressHandler
usually an instance of StorageProgress that will receive periodic updates during the operation. This value can be null.
cancelToken
A CancellationToken to control the operation and possibly later cancel it. This value may be CancellationToken.None to indicate no value.
previousSessionUri
A Uri previously obtained byUploadState.UploadSessionUri that can be used to resume a previously interrupted upload.
Returns
A Task which can be used to monitor the upload.

ToString

overridestringToString()

Details
Returns
This object in URI form, which can then be shared and passed intoFirebaseStorage.GetReferenceFromUrl

UpdateMetadataAsync

Task<StorageMetadata>UpdateMetadataAsync(MetadataChangemetadata)

Updates the metadata associated with thisStorageReference

Details
Parameters
metadata
AMetadataChange object with the metadata to update.
Returns
a System.Threading.Tasks.Task that will return the finalStorageMetadata once the operation is complete.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2022-07-27 UTC.