To upload a file to Firebase Storage, you first create a reference to the full path of the file, including the file name.
Once you've created an appropriate reference, you then call the following to upload to Firebase Storage:
putBytes(): Upload from data in memory
putFile(): Upload a file on the file system
putBytes() method is the simplest way to upload a file to Firebase Storage.
putBytes() takes a
ByteArray and returns an
UploadTask that you can use to
manage and monitor the status of the upload.
putBytes() accepts a
ByteArray, it requires your app to hold the entire
contents of a file in memory at once.
You can upload local files on the device, such as photos and videos from the camera,
putFile() takes a File url and returns an
which you can use to manage and monitor the status of the upload.
You can also include metadata when you upload files. This metadata contains
typical file metadata properties such as
(commonly referred to as MIME type). The
putFile() method automatically
infers the MIME type from the File extension, but you can override the
auto-detected type by specifying
contentType in the metadata. If you do
not provide a
contentType and Firebase Storage cannot infer a default from
the file extension, Firebase Storage uses
See the [File Metadata|Storage - File Metadata] section for more information about file metadata.
In addition to starting uploads, you can pause, resume, and cancel uploads
cancel() methods. Pause and resume
events raise pause and progress state changes respectively. Canceling an
upload causes the upload to fail with an error indicating that the upload
An upload task dispatches
UploadTaskEvents to indicate completion, progress, and errors:
Events are dispatched with a
This object is an immutable view of the task at the time the event occurred.