How to handle Firebase image updates and only download if necessary? - firebase

How would you handle images from Firebase to not download them everytime? I would like to check if the image already has been downloaded and saved to memory and only download it if it differs. Identifying it by name would be my last option, because I currently use the name as a human readable identifier for usability reasons.

Related

Flutter Offline Images Before Uploading

So I'm trying to build an offline-first application with Firebase storage images but am running into an issue. I don't want the user to know when an image is being uploaded to Firebase or not and I want to show the image from the user's local storage immediately. Basically, I want the app to render the local storage image if the image isn't uploaded yet.
I currently use CachedNetworkImage but this requires that the image has been uploaded.
I could create the image URL before uploading it and somehow reference that URL with the local image but I'm not sure how to go about doing that. Any thoughts?
Edit:
I think I'm going to go with this approach: https://www.youtube.com/watch?v=vzrP93xNW8g
It's basically using Firestore track what's been uploaded or not.
Without code we're guessing of course, but making some assumptions here...
Assuming this means not all images will be in their local storage forever:
Could you simply check if an image exists in firebase and if it doesn't present the local image? That is, conditionally build a vanilla Image widget pulling from local storage or a CachedNetworkImage from a URL based on a variable. Perhaps you have a MyImage object with a URL property and pick which widget to build by checking if that is null in the build function.

Retrieve files from firebase storage using only the name of file without an extension

i'm new to firebase and came across this situation where i had to retrieve the files using its name without any extensions like .jpg, .png, .mp3, .mp4 etc... The Actual problem is that I'm saving the files with specific names that i've already decided, but the extension is automatically added using some functions. So I know the names of the files (bee,car,bus,etc...) but not the actual name (bee.jpg, car.png, bus.gif, etc...) thus don't know what i'm supposed to do, to get the download url of the file using only the prefix names(bee,car,bus,etc...) . can somebody help me.....?
The first approaches I can think of:
Use the API to list all files and then find the ones whose base name matches what you're looking for
Store the files with the base name (so remove the extension from the stored files), so that your lookup works.
Store more information about each file in a database (such as Cloud Firestore, or Firebase Realtime Database) and perform the search on that.

How To pull photo down and display it from firebase?

I am making a react native app with expo and firebase. I have uploaded photos to firebase successfully as a blob but want to be able to pull the photos down from firebase and display them to the user. I need to be able to display the user's profile photos whenever they log out or back into the app.
I am not finding any documentation in Expo/React Native/Firebase about downloading. I am only seeing docs on uploading and blobs.
Can anyone point me in the right direction? Is uploading the blob form of the photo and downloading it the correct way to save photos from a user's phone to the database?
These are the resources I have reviewed:
https://firebase.google.com/docs/storage/web/download-files
https://docs.expo.io/versions/latest/sdk/imagepicker/
https://github.com/expo/firebase-storage-upload-example/blob/master/App.js
https://forums.expo.io/t/uploading-images-without-react-native-fetch-blob/981/7
The Cloud Storage SDK from Firebase for JavaScript doesn't have any methods to directly download the bytes from a file.
The way to download the data is through the download URL. So you first get the download URL of the file you're interested in, and then download the data with for example an XMLHttpRequest (as shown in the example in the documentation), or with a similar method for your platform to download data from a URL. For expo the latter seems to be FileSystem.downloadAsync(...).

Make files public from Google Compute Engine

I'm running RStudio server on an instance of Google Compute Engine. My RScript creates a map file that I would like to include in a public web site.
The file gets created OK.
Separately, I've also created a bucket and can upload images to it, viewing them from a web browser with a URL like this: https://storage.googleapis.com/...
Still, I'm confused as to how to make the image created by the R script viewable by a browser. Does the image have to find its way over to a bucket? Or is it viewable where it is somehow?
There are infinite possible solutions depending on what you want to implement and how much time you want to spend on it (and if you are the only one accessing or not and if you can share the file or they are sensible), therefore I will provide you some hints:
The easiest one is to upload the file to a Google Storage Bucket, then you can control who can access that link (a single user, a domain or everyone), it could be access by accessing with the browser with the following link:
https://storage.googleapis.com/namebucket/folder1/folder2/nome_file
There is no graphical interface, you will need to know the address to download the file (at the end it is enough to know the name). You will need to create a small script to make sure every time a image is available to upload it to the bucket and to make it public available. Or you can decide to make he bucket itself public.
The second possible solution is to do the same but to create an html page REALLY simple, basically a list of links to the files in the bucket, each time you upload a file to the bucket you update the html file. At least you would solve the issue regarding the knowing the names and you can navigate it a bit.
<html><body>
This is a link
</body></html>
If you need to expose the resources to more people, or you would like to have something more "nice" graphically you will have to spend more time and build a decent frontend. You can follow thousands of different approaches.
You have really thousands of possibilities.
P.S.
Documentation regarding uploading a file to bucket.
Documentation regarding managing access to file stored.
Notice that in this way depending on the extension of the file you want to share the browser behaves differently, a .txt, a .jpg are shown an .exe is downloaded.

In servlets, is it correct to check the magic number of uploaded files

I am tasked with handling uploaded files in a portal environment. To this end, the user should be authenticated at the point of uploading files. Although the uploads should only be of a certain type (JPG, PDF and PNG), I am aware that the checking of the file types at the client site can be easily spoofed. Do others in a similar environment check the magic numbers of the uploaded files at the server side before storing uploaded files or, as the user is authenticated, simply store the file?
From perusing the web, I can see how to check the file type, however, I have been unable to ascertain whether or not this is common practice in a portal based environment.
Many thanks!

Resources