I initialize and open the Hive database box in my main.dart file and perform the crud operation. App freezes when I reload the app but unfreeze when I remove the "await" keyword behind the Hive.openBox();
await Hive.openBox(ExpenseBoxName); butthe app will stop performing the database operations.
The third snippet is where I performed the crud operation
initialize the database like this
void main() async
{
WidgetsFlutterBinding.ensureInitialized();
final document = await getApplicationDocumentsDirectory();
Hive.init(document.path);
await Hive.openBox<String>(datbase_name");
runApp(MyApp());
}
Related
Hi I am working on react project ,I want to download huge files ( more than 2.5gb) from azure blob storage to react application , ( scenario is when user click on export button I have text files in azure blob storage I want them to be downloaded to local system ) , I have been looking at few approaches, since I am new to azure I am bit confused
using azure AD we can get access to azure blob storage but since my application is hosted on app service how we can connect these two together or we can have direct access to files through azure app services ?
approach I am currently looking at : here
If all the resources are from azure, then we should use manage identity or service principle (which also use manage identity under the hood) link in your case.
In your case, you have two azure resources
Azure blob storage
App Service (which hosted as reactjs application)
So Here is there is step by step explanation to how you connect and read blob
In AppService(which hosted as reactjs application)
Go to your Appservice
Then Click on Identity in Left panel
Then On System assigned managed identity
After clicking save button then it generate Object Id.
In Azure Blob Storage
Go to Your blob storage account
Clicked Access Control(IAM)
Click Role Assignment (RBAC)
Click Add > Add Role assignment
Select Role as per your need like Storage Blob Data Reader
Click Next > Select Managed Identity > Select Member
Then Select your Subscription then App Service
Then List of Managed identity are shown > Select your App Service one which need to connect with storage
Then click on Select and then Next
Then You get the below screen. Match object id which generated in step 4 to below grid
Then Click Next > Next > Review + assign
Now In React Js Application
We can add these two Dependencies in package.json and do an npm i to install.
Now connect blob storage with DefaultAzureCredential from #azure/identity package :- when we give permission /access of one azure to another azure resource directly using service principle or managed identity then we use default azure credential then azure automatically validate them.
Code
For Import package
import { DefaultAzureCredential } from "#azure/identity";
// we're using these objects from the storage sdk - there are others for different needs
import { BlobServiceClient, BlobItem } from "#azure/storage-blob";
Create service client and container
const blobStorageClient = new BlobServiceClient(
// this is the blob endpoint of your storage acccount. Available from the portal
// they follow this format: <accountname>.blob.core.windows.net for Azure global
// the endpoints may be slightly different from national clouds like US Gov or Azure China
"https://<your storage account name>.blob.core.windows.net/",
new DefaultAzureCredential()
)
// this uses our container we created earlier
var containerClient = blobStorageClient.getContainerClient("your container name");
Get list of blob
let blobs = containerClient.listBlobsFlat();
for await (const blob of blobs) {
console.log(`Blob ${i++}: ${blob.name}`);
}
Download blob
const blobClient = containerClient.getBlobClient(blobName);
// Get blob content from position 0 to the end
// In Node.js, get downloaded data by accessing downloadBlockBlobResponse.readableStreamBody
const downloadBlockBlobResponse = await blobClient.download();
const downloaded = (
await streamToBuffer(downloadBlockBlobResponse.readableStreamBody)
).toString();
console.log("Downloaded blob content:", downloaded);
// [Node.js only] A helper method used to read a Node.js readable stream into a Buffer
async function streamToBuffer(readableStream) {
return new Promise((resolve, reject) => {
const chunks = [];
readableStream.on("data", (data) => {
chunks.push(data instanceof Buffer ? data : Buffer.from(data));
});
readableStream.on("end", () => {
resolve(Buffer.concat(chunks));
});
readableStream.on("error", reject);
});
}
For More Details, Go through the below links
Azure Storage Blob client library for JavaScript - version 12.12.0
Quickstart: Manage blobs with JavaScript SDK in Node.js
Currently using Firebase's Realtime Database with my react app. When writing with the following:
const db = realtimeDatabase.getDatabase(app);
realtimeDatabase.set(realtimeDatabase.ref(db, 'test/' + entry), {
test: "test",
});
It does not throw an error or write to the database. When checking the network tab in developer tools, the requests that start with
.lp
Appear as red with no status code and are denoted as cancelled.
Currently working on a React/Typescript/Firebase Firestore project. When writing Jest-tests for some actions/functions that are called from the UI, I ran into the following problem:
In the test file I'm able to setup the firestore client using the v9 api and make it talk to emulator
const app = initializeApp(config.firebase);
const firestore = getFirestore(app);
connectFirestoreEmulator(firestore, "localhost", 8080);
In addition I also found out how to setup the admin client and make it talk to emulator
process.env.FIRESTORE_EMULATOR_HOST = "localhost:8080";
const serviceAccount = require("../../../my-key.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
...config.firebase
});
The test itself looks something like this:
describe("createCompanyAndRating action", () => {
test("call createCompanyAndRating and make sure it creates a proper rating entity", async () => {
// omitted: set testRatingFormState and other test data that are passed as args and
// pass in the firestore db client
const {
ratingId,
companyId,
} = await createCompanyAndRating({
ratingFormState: testRatingFormState,
visitorId: testVisitorId,
firestore,
});
// verify result by fetching the rating entity from the emulator db using the admin client
const ratingPath = `companies/${companyId}/ratings/${ratingId}`;
const ratingSnap = await admin.firestore().doc(ratingPath).withConverter(ratingConverter).get();
const rating: Rating | undefined = ratingSnap.data();
// omitted: verify result with some Jest expect-statetments...
});
})
My problem is now that the Firestore security rules apply and only authenticated users can write docs in the collections used in the createCompanyAndRating function, so the test already throws an error when calling that function.
In this scenario I'm not interested in testing the security rules per se.
Is there a way to bypass the security rules for the test?
If yes, how do I have to setup the firestore client?
Is there even the possibility to somehow impersonate a user in the test?
In addition, please note that I can't to pass the admin client into the createCompanyAndRating function as the admin client API is different from the v9 firebase API that I'm relying on in the createCompanyAndRating function implementation (tried and it didn't work and not only because some type errors in the way).
Maybe my whole approach is a little misguided and I should rather concentrate on testing the internals of the createCompanyAndRating function where I do a lot of factory stuff that could be tested without db interaction.
Anyway, any help/guidance is much appreciated.
Thanks for confirming that I was looking in the right place (i.e. #firebase/rules-unit-testing). Finally figured out what the problem was, missed an "await" in createCompanyAndRating, so the firestore admin instance wasn't getting the data (and I though it was a admin config issue...) Thanks!
I have an application that sends data to the firebase realtime database. Now I'm creating a dashboard to manage this data. At the moment I need to receive a notification on the dashboard when the user sends some new data to the firebase. I need to receive a message with the data id he sent and submit a notification similar to a social network.
I'm using FCM, I've already configured and tried to implement the onCreate () function. But when the bank is upgrading, this function is not being performed.
I'm implementing the code in the dashboard
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.makeUppercase = functions.database
.ref("users")
.onCreate((snapshot, context) => {
const original = snapshot.val();
console.log(original);
});
I'm actually lost on how to do this, I read the documentation, but I didn't quite understand the correct steps to follow. Is there anything I should do before that? Or is this method of doing wrong?
I have a GWT application which has form. If user enters data and submit i have to store the data into google datastore and also an JSP application which is running on tomcat server. I found this is done through Task in GAE GAE Push Task from this i am calling a servlet in my gwt application and in that servlet URL fetch There i have to code to send data to another application and call the servlet to insert data. Can anyone give me how to do it(By a simple example). Is this a correct approach or any other way to do this correctly?
I have done it successfully added a push queue task in server side and called a servlet from there which is registered in guice. then in that servlet i called the fallowing lines
Task queue code
Queue queue = QueueFactory.getDefaultQueue();
queue.addAsync(TaskOptions.Builder.withUrl("/userServlet").method(Method.GET).param("userName", userName).param("pwd", pwd).param("mail",mail));
and userservlet has fallowing code to connect to theother application
final String url_Name = "http://xxxxxxxx.com/AddUserServlet";
//final String url_Name = "http://localhost:8181/jos-webapp-1.2.1/AddUserServlet";
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
HTTPRequest request = null;
HTTPResponse response= null;
try{
URL url = new URL(url_Name);
request = new HTTPRequest(url, HTTPMethod.POST);
String body = "userName="+uName+"&pwd="+pwd+"email"+email;
request.setPayload(body.getBytes());
response = fetcher.fetch(request);
}catch(Exception ex){
ex.printStackTrace();
}
In my JOIDS(second application) I wrote a servlet(AdduserServlet) and used someget the data. Any better solution than this will be accepted