Can we use in MeteorJS binary inserted png to the mongodb ? Or do we have to stick base64 ?
I inserted tons of binary png to mongodg for saving the spaces.
I can perfectly utilize it from my C++ codes.
But now need some web frontend.
There are packages like ostrio:files that will do a lot of the work for you. Inserting files into the database works, but puts a load on the database and app to do basic file serving activity, which is better done by something like AWS S3.
Alternatively there is a great service called Filestack https://www.filestack.com/ which is very easy to integrate to, and has a good upload control complete with cropping and resizing. You can just store the image URL's in your database. Quick to implement, and offloads from your server.
Related
How can I store images in a MongoDB through Flutter/Dart?
We are developing an android application using MongoDB and Flutter. We want to store images during the registration of users in our app. I already referred the mongo-dart documentation but still, I can't find any solution about this.
I would suggest encoding your images to Base64 format. Then you can store them technically as plain text. There is a base64Encode function in dart:convert package.
You can also check this discussion: how to convert an image to base64 image in flutter?
MongoDB has GridFS for storing files:
A convention for storing large files in a MongoDB database. All of the official MongoDB drivers support this convention, as does the mongofiles program.
It looks like mongo-dart supports it as well although it's missing the documentation.
I trying to figure the best way to store an image in a database using typeorm. Should you store it as a data url or as a buffer? Currently it would be over kill for my application to store it in a CDN hence the reason I want to store it in the db.
My thought was to save it as a data url as well as a field for the image name.
Appreciate any into!
It really depends much on your production infrastructure. By the way, IMHO the best way would consist in storing at least the file path where the content gets uploaded to (local, bucket, etc..) and the file's mimetype.
I have set up my Mongodb database have connected successfully.
However my project is to create an online cookbook.
My database currently is various recipes but with each document I want an image to be linked to it.
I know I can use gridFS but I would prefer to store the images in the same place as the recipes.
I have seen I can use base64 but that is no appearing for me
I am very new to using Mongo and some advise is greatly appreciated
Store the images in s3 bucket and storing the path of the s3 image in the DB.
Using s3 url you can access the image.
I have a php app running on several instances of Google Compute Engine (GCE). The app allows users to upload images of various sizes, resizes the images and then stores the resized images (and their thumbnails) in the storage disk and their meta data in the database.
What I've been trying to find is a method for storing the images onto Google Cloud Storage (GCS) through the php app running on GCE instances. A similar question was asked here but no clear answer was given there. Any hints or guidance on the best way for achieving this is highly appreciated.
You have several options, all with pros and cons.
Your first decision is how users upload data to your service. You might choose to have customers upload their initial data to Google Cloud Storage, where your app would then fetch it and transform it, or you could choose to have them upload it directly to your service. Let's assume you choose the second option, and you want users to stream data directly to your service.
Your service then transforms the data into a different size. Great. You now have a new file. If this was video, you might care about streaming the data to Google Cloud Storage as you encode it, but for images, let's assume you want to process the whole thing locally and then store it in GCS afterwards.
Now we have to get a file into GCS. It's a PHP app, and so as you have identified, your main three options are:
Invoke the GCS JSON API through the Google API PHP client.
Invoke either the GCS XML or JSON API via custom code.
Use gsutil.
Using gsutil will be the easiest solution here. On GCE, it automatically picks up appropriate credentials for your service account, and it's got several useful performance optimizations and tuning that a raw use of the API might not do without extra work (for example, multithreaded uploads). Plus it's already installed on your GCE instances.
The upside of the PHP API is that it's in-process and offers more fine-grained, programmatic control. As your logic gets more complicated, you may eventually prefer this approach. Getting it to perform as well as gsutil may take some extra work, though.
This choice is comparable to copying files via SCP with the "scp" command line application or by using the libssh2 library.
tl;dr; Using gsutil is a good idea unless you have a need to handle interactions with GCS more directly.
I want to store images and other documents in a PostgreSQL table, along with a thumbnail of each image. The original document and the thumbnail would be two separate bytea fields. PostgreSQL is running on Linux.
Because the image data could come from several different applications, I'd like to have the image processing code (for creating the thumbnail) within PostgreSQL as a function, rather than each individual application having to create the thumbnail. Is there any way for PostgreSQL to be able to create a thumbnail of an image?
PostPic sounds like the Postgres extension you are looking for.
As described in their wiki you will be able to resize and create thumbnails with ease:
FUNCTION thumbnail(i image, size INT) RETURNS image
FUNCTION resize(i image, w INT, h INT) RETURNS image
May I suggest instead that all your applications instead use a common interface or an API?
For my photography platform, I have an Upload API that everything goes through, although there are about 4 different ways to actually perform an upload (browser, desktop, phone, and software plugin). The Upload API then has the functionality to manipulate the images with some powerful and performant libraries (I'm using Python, so PIL), and then save them to the database (actually, I'm saving to a file system and referencing them in the DB, but the idea is the same).
An alternative is that a thumbnail generator service could reside outside of your database, and then occasionally loop through all your rows that don't yet have a thumbnail generated, generate one, and then store it back into Postgres.
You're asking for a world of performance hurt if you do end up doing image manipulation inside of Postgres, particularly on the memory side.
Is there any way for PostgreSQL to be
able to create a thumbnail of an
image?
No. PostgreSQL is a database engine, it just allows to store and retrieve data, and to some extent manipulate it. But doing some image processing inside it would go way too far.
Image resizing should be done outside the database.
And, as other commenter says, consider also the option of not storing the image data inside the database - only some path or locator. This is optional, but frequently it's more practical.
Read some related questions:
Storing Images in DB - Yea or Nay? ,
Storing a small number of images: blob or fs?
I've only ever hacked a few trivial functions in perl, but chances are there are plenty of appropriate libraries if you install pl/perlu.
If pl/perl2 is not an option, configure pl/perl accordingly:
plperl.use_strict = true
plperl.on_init = 'use stuff1; use stuff2;'
Simplest answer: Do not store images in database. It's slow, ineffective, doesn't scale, makes backups take longer.
And when you'll store them on filesystem - just add middleware to resize them, or a simple daemon which will resize all new images.