Home > Mobile >  Download byte range requests support for firebase storage
Download byte range requests support for firebase storage

Time:03-26

Am trying to narrow down a problem and knowing if firebase storage supports byte range requests for video downloads will help. I can't seem to find that information anywhere. My web app includes video streaming functionality (You-tube style) and I wonder if this is the best choice. If not what better alternative to host the videos?

I have already implemented this as follows but my videos plays in all devices and browsers except iphones and ios devices:

<video width='100%' height='315' poster='{{ value.image }}' controls loop muted playsinline>
       <source type='video/mp4' src='{{ value.video }}'>
</video>

Based on extensive research here and other resources online,

Solutions seems to be adding controls playsinline muted to the video tag seemed to work, mine didn't with these.

The other problem was video-container type. Have confirmed that mine is mpeg4 container and displayed with video/mp4 in the source type.

Last issue I see is that server might not support byte range requests, am trying to determine if this is it with firebase before deciding to move on to another video storing solution. (And any suggestions for these?)

Thanks.

CodePudding user response:

Cloud Storage for Firebase stores your files in a Google Cloud Storage bucket, making them accessible through both Firebase and Google Cloud. This allows you the flexibility to upload and download files from mobile clients via the Firebase SDKs for Cloud Storage. In addition, you can do server-side processing such as image filtering or video transcoding using the Google Cloud Storage APIs.

As for your concern, as stated above, Google Cloud Storage has support for byte requests which in turn Firebase Storage also support it. Here's a sample code from Download an object using a byte range:

from google.cloud import storage


def download_byte_range(
    bucket_name, source_blob_name, start_byte, end_byte, destination_file_name
):
    """Downloads a blob from the bucket."""
    # The ID of your GCS bucket
    # bucket_name = "your-bucket-name"

    # The ID of your GCS object
    # source_blob_name = "storage-object-name"

    # The starting byte at which to begin the download
    # start_byte = 0

    # The ending byte at which to end the download
    # end_byte = 20

    # The path to which the file should be downloaded
    # destination_file_name = "local/path/to/file"

    storage_client = storage.Client()

    bucket = storage_client.bucket(bucket_name)

    # Construct a client side representation of a blob.
    # Note `Bucket.blob` differs from `Bucket.get_blob` as it doesn't retrieve
    # any content from Google Cloud Storage. As we don't need additional data,
    # using `Bucket.blob` is preferred here.
    blob = bucket.blob(source_blob_name)
    blob.download_to_filename(destination_file_name, start=start_byte, end=end_byte)

    print(
        "Downloaded bytes {} to {} of object {} from bucket {} to local file {}.".format(
            start_byte, end_byte, source_blob_name, bucket_name, destination_file_name
        )
    )

For additional reference, you may check out API Reference Documentation.

  • Related