0
votes

Scenario : I am downloading image/video files from firebase storage and displaying them in a list.

Issue : The response is pretty slow. It is taking way too much time to download images/videos.

CODE :

Directory tempDir = await getTemporaryDirectory();
final File tempFile = File('${tempDir.path}/$fileName');
if(tempFile.existsSync()){
  await tempFile.delete();
}

await tempFile.create();
var ref = FirebaseStorage.instance.ref(path); 
// final DownloadTask task = ref.writeToFile(tempFile);
final DownloadTask task = ref.writeToFile(tempFile);

await task.then((value) => {
  file = tempFile
  //Also delete the temp file
  // await tempFile.delete();
});

RESULT : The files gets download successfully but response is way too much long. Any suggestions on how to make downloads faster. I also tested the response on real device with a release apk but still way too much slow downloading from Firebase Storage. I am using internet connection of 20MBPS so it's pretty decent speed to download data. Also, the uploading of files to firebase storage is pretty decent and i haven't found any issues there.

NOTE : I am currently using Firebase Free plan for development. Is that affecting the download response ? Really need some experts advice here.

IMAGES ON FIREBASE Images on Firebase

VIDEOS ON FIREBASE enter image description here

2
What is "pretty slow" and "way too much time"? What region are you operating from, and what region is your storage hosted in? Also, have you tested your connection using some form of measure (perhaps speedtest.net or similar) to verify that you indeed get your expected throughput?Robert Sandberg
The region is by default the firebase selects on creating a default bucket. I forgot about which region i selected. Also, i have tested my internet connection. The download speed is 2mbps and same goes for the upload. Basically, i am creating a social app like 9gag with a list of posts containing images/video. As you can see above the images are very small in size so the downloading of that images should be fast but it takes atleast 2 seconds approximately to download an image and then move on to the next image. So, if i am downloading 10 images then it is taking approximately 15-20 secondFiaz Ali
This time for downloading is pretty much high even for images which are only kbs of size. If i try to download videos then it would go upto a minute to download them and show them. Also, the firebase storage window doesn't show much controls on how to change a region for default bucket and it's also not showing which is the current region. Before posting the question, i have researched about any possible solution on what's going wrong but haven't found anything useful though.Fiaz Ali
Some people commented out that if you use an FTP server then the download speed is 10 times faster then the firebase storage. One commented about making the firebase public by changing the rules of the firebase storage. I also did that but response time was the same. Some people commented out that they had moved on to Amazon Storage because it's much faster then Firebase storage. It's hard to accept that a platform provided by google can be slow. What am i missing ?Fiaz Ali
The region for the project is nam5 (us-central)Fiaz Ali

2 Answers

1
votes

First an answer your specific question: No, Firebase Spark plan won't affect download time.

It's hard to write a good answer for this very broad question. But based on the answers you provided in the comment... here goes:

If you are sitting in a different region than the US (which you had your bucket in), that will of course impact the download time. So a suggestion is to make sure that your storage is in the region where you have most users, or implement load balancing.

Have you timestamped the actual download time? Narrowing down whether or not it is that part that actually does the downloading that takes time, or some other part of the code? So just before you start the actual download, and then right after it is finished, not including other parts. That way you can isolate where a lot of time is. Check it with something like this:

final before = DateTime.now();
<... specific code that does the downloading>
final difference = DateTime.now().difference(before);

Then another thing to take into consideration is how you implement the fetching of each image. If you know that you will download 10 images. Instead of doing it synchronously one after another, consider doing that fetching asynchronously and waiting for the slowest. Perhaps something like this:

final allImages = await Future.wait([
  downloadImage(1),
  downloadImage(2),
  downloadImage(3),
  ...
]);
0
votes

I managed to reduce the download time to access files from Firebase Storage. Here are some of the steps i did :

1 - All Firebase projects are basically Google Cloud projects. Didn't know about that as i am new to Firebase and server-side environment. Understanding Firebase Projects

2- I have found an answer regarding fast access from firebase storage bucket which is basically a google cloud bucket. Firebase Storage very slow compared to Firebase Hosting

The solution posted by Zywy. Aside form making the bucket public, he mentioned that you need to install Google Cloud SDk to make files(which are going to be uploaded to the bucket) public. I think that is the case for native android development and not for Flutter. I didn't installed the Cloud SDK. I just make the bucket public and all the files that are then uploaded to the bucket are then also public. Correct me if i am wrong here.

So basically what i did was to make my bucket puclic by default. Here is a link on how to do that : Making Data Public

After making the bucket public, the image files which were taking 150-200 ms to download get reduced to 10-30 ms(millliseconds).

Anybody who is new to Firebase like me and stuck in the same situation should follow these steps.

Also, i am still learning about Firebase so if anyone has some expert advice on making this answer better or if i am wrong about anything about this issue then let me and whole community know about this.

Also, i am still searching about the security issue on making the bucket public. Is it harmful or not? So, if any expert out there on Cloud Platform security then let us know.

Thanks to Robert Sandberg for the early response on this issue.