I am trying to figure out the best way to save an image (png) that is stored in my assets folder to my firebase database so I can retrieve that image/path for later use. Essentially this is what I want:
// savedPath was stored and then retrieved from database
let savedPath = '../assets/images/example.png'
return (<Image source={require(savedPath)} />)
However, if I just save the path as a string, I can not insert it into the image source like this and it throws an error. I am wondering what my alternative option is to achieve that same thing as the example above?
You can use firebase storage bucket https://firebase.google.com/docs/storage/ to store all your assets
Then you can store the file name/path in your database and access it from there.
Related
I am currently trying to read pdf files stored in my google cloud storage. So far I have figured out how to read one file at a time from my google cloud storage, but I want to be able to loop through multiple files in my google cloud storage without manually reading them one by one. How can I do this? I have attached my code below.
To iterate all files in your bucket move your code for downloading and parsing in the for loop. Also I changed the for loop to for blob in blob_list[1:]: since GCS always prints the top folder in the first element and you do not want to parse that since it will result to and error. My folder structure used for testing is "gs://my-bucket/output/file.json....file_n.json".
Output when looping through the folder (for blob in blob_list:):
Output files:
output/
output/copy_1_output-1-to-1.json
output/copy_2_output-1-to-1.json
output/output-1-to-1.json
Output when skipping the first element (for blob in blob_list[1:]:):
Output files:
output/copy_1_output-1-to-1.json
output/copy_2_output-1-to-1.json
output/output-1-to-1.json
Loop through files. Skip the first element:
blob_list = list(bucket.list_blobs(prefix=prefix))
print('Output files:')
for blob in blob_list[1:]:
json_string = blob.download_as_string()
response = json.loads(json_string)
first_page_response = response['responses'][0]
annotation = first_page_response['fullTextAnnotation']
print('Full text:\n')
print(annotation['text'])
print('END OF FILE')
print('##########################')
NOTE: If you have a different folder structure versus the test made, just adjust the index in the for loop.
In the new Firebase console I can't edit the name of nor clone nor move any node (change parent) of a realtime database
I have even tested setting Rules to Public.
Is this by design ? What then, is the use of this console ? ONLY to change child values ?
There is indeed no way to clone a node or rename a key in the Firebase Database console. Since the Firebase Database API doesn't have a clone/rename operation, we also don't have an equivalent in the UI.
Note that this operation also wasn't possible in the previous Firebase Dashboard, for the same reason. It has nothing to do with your security rules nor with the new release.
If you want to move a node to a new location, you'll have to emulate it:
Go to the Database tab in your Firebase Console
Navigate your JSON tree until you've selected the node that you want to move
Open the overflow menu (three vertical dots: ⋮) on the right and select Export JSON. Save the file to your local disk.
Delete the node from the JSON tree
Navigate your JSON tree to the location where you want to move the data
Open the overflow menu (three vertical dots: ⋮) on the right and select Import JSON. Select the file from your local disk.
In the new Firebase console I can't edit the name of nor clone nor move any node (change parent) of a realtime database
I have even tested setting Rules to Public.
Is this by design ? What then, is the use of this console ? ONLY to change child values ?
There is indeed no way to clone a node or rename a key in the Firebase Database console. Since the Firebase Database API doesn't have a clone/rename operation, we also don't have an equivalent in the UI.
Note that this operation also wasn't possible in the previous Firebase Dashboard, for the same reason. It has nothing to do with your security rules nor with the new release.
If you want to move a node to a new location, you'll have to emulate it:
Go to the Database tab in your Firebase Console
Navigate your JSON tree until you've selected the node that you want to move
Open the overflow menu (three vertical dots: ⋮) on the right and select Export JSON. Save the file to your local disk.
Delete the node from the JSON tree
Navigate your JSON tree to the location where you want to move the data
Open the overflow menu (three vertical dots: ⋮) on the right and select Import JSON. Select the file from your local disk.
In this blog post, some prerequisite code for getting started using SQLite in Windows Store Apps is given, for adding to the OnLaunched method of App.xaml.cs:
// Get a reference to the SQLite database
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");
My question is: Can I use any arbitrary value to replace the "customers.sqlite" part, or does it have to match something else in my code, such as the name of my table definition class (in my case "PhotraxCoreData.cs" which, according to Mr. Green's suggestion, I added below a newly-created "Models" folder)?
My understanding is that, once I've got those classes defined (I do), and the code above in App.xaml.cs, along with this there (adapted for my SQLite classes):
using (var db = new SQLite.SQLiteConnection(this.DBPath))
{
// Create the tables if they don't exist
db.CreateTable<PhotraxBaseData>();
db.CreateTable<PhotraxNames>();
db.CreateTable<PhotraxQueries>();
}
...SQLite tables based on those classes I specified will be created, and have the name "customers.sqlite" (provided I don't change it).
So, can I use:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "platypus.sqlite");
...or must it be something like:
this.DBPath = Path.Combine(
Windows.Storage.ApplicationData.Current.LocalFolder.Path, "PhotraxCoreData.sqlite");
That database name is just a file name.
The directory must be accessible by your app, but the file name can be anything.
AS CL says, the file name can be anything the app has direct access to. Windows Store apps have limited access to the file system, so the sqlite database must be in either the apps install location (read only) or it's app data folder (read write). A common pattern is to ship a seed database in the app package and then copy it from the install location to app data on first use so it can be written to.
I have 2 different project. One is supposed to upload images (admin) and the other is supposed to show them.
I was writing something like "/Contents/images/image path"... But wait! I will I upload the images from the application into that address?
Any help and suggestions please.
If you have two applications that will interact with the same files, it's probably better to have an ImageController with an action that allows you to upload/download the image rather than storing them directly as content. That way both applications can reference the same file location or images stored in a database and manipulate them. Your download action would simply use a FileContentResult to deliver the bytes from the file. You can derive the content type from the file extension.
Example using a database. Note that I assume that the database table contains the content type as determined at upload time. You could also use a hybrid approach that stores the image metadata in a database and loads the actual file from a file store.
public class ImageController : Controller
{
public ActionResult Get( int id )
{
var context = new MyDataContext();
var image = context.Images.SingleOrDefault( i => i.ID == id );
if (image != null)
{
return File( image.Content, image.ContentType );
}
// or you could return a placeholder image here if appropriate.
throw new HttpException( 404, "The image does not exist" );
}
}
An alternative would be to incorporate your administrative interface in an area of the same application rather than in a separate project. This way you could reuse the content/images directory if you wanted. I find that when you have dynamic images the database or a hybrid approach works better from a programming perspective since it's more consistent with the rest of your data model.
you could try like this..
Let's assume that all of your images are in Project A and you want to use the same images in Project B.
Open Project B with Visual Studio. In the Solution Explorer, right click your Project Name and select "Add Existing Item...".
Browse to the physical location on disc where your images in Project A are stored and select the files that you want to import.
You'll then be able to access those images from project A in Project B.