I have a simple Firebase web application which is hosted on Firebase static hosting service where you can upload a picture with some textboxes and it gets stored in the Firebase realtime database like this:
{
name: string,
description: string,
picData: base64 string
}
Now I would like to serve this image via a HTTP Get request. Is that even possible?
Something like: http://myawesomewebsite.com/getImage?name=x
The same like https://picsum.photos/ does it.
To be able to serve content from the Firebase Realtime Database on a GET request, you will have to extend the functionality of Firebase Hosting using Cloud Functions for Firebase or Cloud Run.
The Connect Functions to Hosting section explains the steps required to serve a "bigben" page that could quickly be adapted to decode the base64 in your database and return the data. Be wary that you must also specify the image's mime type (e.g. image/png, image/jpeg) when serving the image which you don't currently store in your database.
While possible, I would recommend storing your images in Firebase Storage instead. This will help keep track of meta data such as sizes, mime types and upload times whilst not clogging your database with files stored in Base64. Images stored on Firebase storage can also be retrieved via a GET request by the client SDKs or served from a Cloud Function.
Related
Background
We are using the following api to fetch image data uploaded from our user via bot.
The API reference is the following.
https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-connector-api-reference?view=azure-bot-service-4.0#get-attachment
And the use case is the following.
User pasted image along with text and send message to bot.
The following image is the [bot side].
We are fetch the pasted image data and show it on [our app side].
The following is our app side.
Issue
But we found that for the images uploaded [1 month ago], the API returns with 404 http code and we could not get image data anymore.
For the images uploaded recently, The api responsed with 200 and image binary data which we can take usage and show it.
Question
Is it possible that MS side put some restriction for pasted image that uploaded to botframework blob storage more than a month?
It's important to note that the Azure Bot Service's Connector service is not a storage service. When attachments are sent to/thru the Connector, Azure will store the attachment for no more than 24 hours.
If you are needing to access attachments sent days/weeks/months ago, then you should utilize Azure Blob Storage, or some equivalent service, to meet those needs.
Im using amazon lambda for the backend for the chatbot and I have no idea how to let the chatbot generate the image from my website. I read about custom payload but the documentation is very sparse and lack in information. I tried to send it with html tags in the content and in json format but both did not work. Dialogflow for example has very straightforward documentation in generating the image but somehow amazon lex makes it hard for me.
Please have a look at this answer on a similar question: https://stackoverflow.com/a/69633494/8880593
Perhaps consider storing the images in an S3 bucket then returning the image link using the ResponseCard or GenericAttachment feature.
You could secure the image through the use of presigned URL's. Storage capacity on S3 can be managed through the implementation of a lifecycle policy to automatically delete these images after a specified period of time.
S3 - Sharing an object with a presigned URL
S3 - Expiring Objects
I'm sending an email using the SMTP protocol in Django. When I send the image link it is like this:
https://example.com/images/pic1.jpg
But Gmail converts it to something like this:
https://ci5.googleusercontent.com/proxy/vI79kajdUGm6Wk-fjyicDLjZbCB1w9NfkoZ-zQFOB2OpJ1ILmSvfvHmE56r72us5mIuIXCFiO3V8rgkZOjfhghTH0R07BbcQy5g=s0-d-e1-ft#https://example.com/images/pic1.jpg
I tried the image URL proxy whitelist setting. It is showing the preview of the image.But image links are not working.
PS: I have also tried methods suggested here to no avail.
Update 1:
The images are stored in the AWS s3 bucket. If I make them public then they work fine. But I can't make them public.Is there any other way?
The images are stored in the AWS s3 bucket. If I make them public then they work fine. But I can't make them public.Is there any other way?
The short answer is "no" if you want to keep referencing image through URLs as GMail's image proxy needs access to your images over the "public" internet one way or another.
This question is a bit off topic as it has little to do with Django but if you're using GMail for business you can configure which URLs should not go through the proxy. This should allow you to prevent images served from your "private" S3 bucket URL from being proxied. Note that this will only work for GMail accounts within your business domain; the images will be proxied and fail to load if the email is sent to a non-business or a different business Gmail account for example.
One another way you could avoid proxying completely it to attach the image in the email instead of referring to it through an URL. You can refer to this answer for how to achieve that https://stackoverflow.com/a/3787766/70191.
My single page app is hosted on Google's cloudstore. I love that I don't have to worry about a server. The app is, naturally, javascript heavy.
Now I would like to add a feature where users can store some data, generate a link to be shared with others and retrieve stored data. Think of a pastebin where some snippet of text is saved and a unique link is generated to be shared with others.
In fact, if it helps, think of this as my attempt to create a pastebin without having to setup a server.
It looks like Google's cloud datastore nosql solution is what I want. Given a key, it will return a snippet of text. However, all the examples on the documentation page imply that I have to setup a back end service using python, node, etc.
Questions:
Can't I just read and write from a web page, perhaps using ajax style http call (since I need to get and put text snippets once data has already been loaded)? I believe I can take care of cross-origin issues by changing some configs in the cloudstore static website server.
Obviously I don't want to serve any encryption keys from the web page. I'm hoping that since my site is served from Google as well, I can configure the nosql service handle permissions intelligently for this scenario.
Is there any documentation which shows how to do this correctly?
Google Datastore is not supposed to be used from client side, it's a served side database. You cannot do that w/o having server side code to authenticate, authorize and validate db related requests.
But there're an alternative. Firebase is a ready to use backend for client side applications, including Javascript apps. It's a separate project, that belongs to Google but not (yet?) part of Google Cloud. Take a look - https://www.firebase.com/
Although the API Rest is still beta, it is possible now to connect from a web client or anything RESTful capabilities. https://cloud.google.com/datastore/reference/rest/
When creating a service like Google Analytics or StatCounter, I want to do it a little bit different in the data storage part:
A user visits my client's website.
JS code or 1 pixel image is downloaded from my server.
Request sent to my server, where the data is processed.
Things like country, returning customer, bounce rate, etc are calculated.
Instead of storing this data in my server, I want to store it in the client's server.
The client is an individual or business who is using my "service" for web analytics of their website.
Assuming that they are prepared to create a db schema that I choose, what is the recommended way to send the data to them to store?
The only thing I can think of is, asking them to give me a URL in their server, to which I will POST a JSON string, which they can store or do whatever they want.
Apart from HTTP POST, are their any other choices I have to send the data to them?
You could store the data on your own server then provide a mechanism for the client to download it. This would save you the burden of entering and testing a different URL for each customer.
It would also mean that you would only need one SSL URL and authentication method for security. Otherwise you would need to make sure each customer has a working SSL and get your script to log onto each of them when it deposits the data.