Bandwidth overflow with video - flutter

I'm testing my app, and analytics say that I used 2 MB/day for the first month of tests. Yesterday I added a function that allowed to upload a video, and in order to test it I uploaded a video (or maybe 2, but surely not more) of less than 10MB of size. Now the problem is that I overflew the allowed bandwidth, using 1.5GB and I don't know why. Should I look at the method where I upload to the storage, or the ones where I download, or both?
This is the only method used to upload a video:
Future<String> uploadVideo(imageFile) async {
UploadTask uploadTask =
storageRef.child("post_$postId.mp4").putFile(imageFile);
TaskSnapshot storageSnap = await uploadTask;
String downloadUrl = await storageSnap.ref.getDownloadURL();
return downloadUrl;
}
While for downloading, since I use Chewie as video player, I have:
Chewie(
controller: ChewieController(
...
videoPlayerController: VideoPlayerController.network(widget.post.mediaUrl)
),
)
I don't know if it could be something else that causes this problem and how to fix it, so if you have any suggestion please tell me.

I understand that you are looking for a way to determine what used the bandwidth in your Firebase Storage causing it to go over the quota.
Firebase logs all requests to storage as per link. You can monitor the Cloud Storage activity for your Firebase project by following the link.
Log events provide insight on what is happening in your app, such as user actions, system events, or errors.
So, after you have configured the FirebaseApp instance, you need to log this in your application by following a process similar to the example mentioned here. This would allow you to record details of when a request is made, the size of the data transfer, and how often it occurred.
Apart from this, you can also open a support request or billing query to Google, where you can ask for a more detailed breakdown of the usage. You may also refer to the link for details on pricing.

Related

How do i know all my changes made to document in offline mode are synced to firestore when i turn on internet in flutter firestore

I am creating flutter app, where I am using Cloud Firestore as a database and I am utilizing its offline capability. the app perfectly works when I am in offline mode it saves documents locally and when I turn on the internet it syncs those documents back to Firestore.
I want to know is there any way to know that all of my documents are synced when I turn on the internet, like some event listener or something?
I didn't find anything in the documentation.
I want to know if is there any way to know that all of my documents are synced when I turn on the internet, like some event listener or something?
Yes, you can know that in Flutter too. So please check the SnapshotMetadata of a QuerySnapshot object, which contains an isFromCache field that:
Whether the snapshot was created from cached data rather than guaranteed up-to-date server data.
If your Flutter project requires you to listen for metadata changes, then please check the official documentation:
If you want to receive snapshot events when the document or query metadata changes, pass a listen to options object when attaching your listener:
final docIdRef = db.collection("collName").doc("docId");
docIdRef.snapshots(includeMetadataChanges: true).listen((event) {
//Your logic.
});
In this way, you'll be able to update the UI elements of your screens, once the data is synchronized with the Firebase servers.

Service Worker caching/playback of videos: what is the most compatible approach?

Im currently working on a small PWA which should also include several local video files offline.
(Using a precache szenario)
I've already noticed that the caching of such files is not straightforward, especially for iOS devices because of the limited range request.
I've already tried this solution proposed at at similar question:
PWA - cached video will not play in Mobile Safari (11.4)
But for me that didn't work either.
They only working solutions I found online used some form of blob handling in combination with either the File API or Indexed DB Storage
https://simpl.info/video/offline/
Is it possible to cache an entire HTML5 video using the Service Worker API for offline use?
As this where rather old posts I was wondering, which strategy would be appropriate concerning current apis (but also targeting older iOs Devices)
Thank you in advance.
If you're willing to go all-in on Workbox, the information at "Serve cached audio and video" should be accurate across multiple browsers and platforms.
If you'd rather handle caching yourself but just want some help creating an HTTP 206 partial response, given an incoming Request and a Response object that you've read from a cache, you can just use the createPartialResponse() method from workbox-range-requests, without using the rest of Workbox:
import {createPartialResponse} from 'workbox-range-requests';
self.addEventListener('fetch', (event) => {
const {request} = event;
if (request.headers.has('range')) {
event.respondWith((async () => {
const cache = await caches.open('media');
const fullResponse = await cache.match(request);
if (fullResponse) {
return createPartialResponse(request, fullResponse);
}
// If there's a cache miss, fall back to the network.
return fetch(request);
})());
}
});
You can also take a look at the createPartialResponse() method's source if you want to implement that yourself.

How to know the amount of requests

I'm using React and Firebase, and when I check the usage on Firestore, I see a lot of request being made. The problem is that I'm not the only one using it, so I don't know if most of them are mine or not. Is there anyway (using console maybe?) to know how many request I'm doing?
There is currently no way to track the source of reads and write happening in Firestore. You can only see the total volume of those requests in the console.

Flutter Saving data locally, Shared Preferences versus Save to file

I am building a calendar app and for that I need to save the data locally. The data is in the form of a Map<DateTime,List<dynamic>>.
I was thinking of using the SharedPreferences plugin for Flutter but on pub.dev it says "Neither platform can guarantee that writes will be persisted to disk after returning and this plugin must not be used for storing critical data." and so I'm hesitant to use it. Is there any advantage to storing data to SharedPreferences over just saving it to a file?
I am not sure how exactly I'll save to a file but I'm thinking of converting it to a String using jsonDecode().
SharedPreferences are usually mostly for Settings etc. It will work most likely, but the performance will not be great (if that is a concern). Your Data will probably be stored just fine, but as it says on pub.dev, it's not guaranteed.
The upside of SharedPreferences is that your Data will be available from anywhere in your App in an easily accessible way.
Saving to a file will also work, but you do have to remember that files you save in the AppDirectory are also not 100% safe from deletion. The Device OS can at any point clear these files. Again, probably not going to be an issue, but I thought i'd mention it.
Usually for on Device storage i would suggest sqflite (https://pub.dev/packages/sqflite). It's simple enough to use and has the best performance and "safety" for your Data.

Is Firebase appropriate in pwa with offline mode?

I'm developing a PWA with Ionic/angular and Firebase/Firestore.
It manage a collection of categorized lyrics. Admins can add/delete/modify lyrics etc. Firestore is very usefull for that.
I want my PWA fully accessible offline after installation. To do that i need to read all collection (300 documents) when app loads in order to cache it. It is an important amount of reads by user, Google charge 300 reads each time app is loaded, and even more with listeners with database changes. I think, my use case is not very adapted to Firestore way to get data.
const lyricsCollection: AngularFirestoreCollection<Lyric> = this.afStore.collection<Lyric>('lyrics', ref => ref.orderBy('title'));
this.lyrics$ = lyricsCollection.snapshotChanges();
My question is: How can i improve my db or app architecture to be more adapted to my needs ?
Thanks