Firebase storage - resize image extension - node.js

i wanted to resize my images, so i installed this resize image extension.
Problem is it only resize image if i upload it on firebase website. Problem is if i upload it through nodejs or flutter, it does not resize..
Do i need to set some metadata or what? Does it only work for firebase website? Or is it possible to somehow trigger extension?
_reference.putData(
await pickedImage.readAsBytes(),
SettableMetadata(contentType: 'image/jpg'),
); ```

Related

Error Loading Preview on Firebase Storage when click on the image

We are making app for school project.. and we use firebase as our database.. when I try to directly upload the image files on firebase storage, I cant view it, theres this message "Error loading preview".. while my other team member can view it on his device.. same thing happen when uploading and retrieving images to our app.. I cant seem to upload and view image(using Piccasso and Glide) on my device.. but my other group member works fine..
Im using my phone to run our app. Storing and retreiving other data works fine except for images.
please help

updating a deployment - uploaded images gets deleted after redeployment to google cloud

So I have a node js web app, this web app has a folder to store images uploaded by users from a mobile app. How I upload the image to the folder is by using the image's base64 string, and using fs.writeFile to save the image to the folder, like this:
fs.writeFile(__dirname + '/../images/complaintImg/complaintcase_' + data.cID + '.jpg', Buffer.from(data.complaintImage, 'base64'), function (err) {
if (err) {
console.log(err);
} else {
console.log("success");
}
});
The problem is, whenever the application is redeployed to google cloud, the images gets deleted. This is because the image folder of the local version of the application is empty - when the user uploads an image, i don't get a local copy of that image.
How do i prevent the images from getting deleted with every deployment? because the app is constantly updated (changes to js or html files), i can't have the images getting deleted with every deployment. How do i update a deployment to only deploy certain files? the gcloud app deploy command seems to deploy the entire project. or should i upload the images directly to google cloud storage?
please help, currently the mobile app isn't released to the public yet, so having the images deleted with every deployment is still not a big problem now, but it will be once it's released to the public. because the images they upload are very important. thank you in advance!
It appears that your __dirname directory you chose may be under /tmp or, if you use the flexible environment, some other directory local to your instance. If so the images will disappear whenever new instances are started (which always happens at new deployment, but it can happen in between deployments as well). This is expected, the instances are always started "from scratch".
You need to store the files that your app creates and you want to survive instance (re)starts on a persistent storage product, like Cloud Storage, see Using Cloud Storage (or Using Cloud Storage for flexible env). Note that you can't use the regular filesystem calls with Cloud Storage, you need to use the documented client library.
As stated in Dan Cornilescu's answer, for user uploaded files, you should store them in Cloud Storage for GAE Standard or for GAE Flexible.
Just as a reference, there is an alternative for those who are using Python 2.7, Java 8 or PHP 5, which is the BlobStore API

Jimp write image to Google cloud storage node js

I'm currently writing images to my filesystem using jimp.
For example: image.write('path')
This cannot be used on Google App Engine because its read only filesystem.
How can I write this to a Google storage bucket? I've tried writestreams but keep getting read only errors so I feel like jimp is still writing to the drive.
Thanks heaps
As I can understand you are modifying some images on your App Engine and you want to upload them to a bucket but you didn't mention if you are using standard or flex environment. In order to do this you want to make your publicly readable so it can serve files.
Following this Google Cloud Platform Node.js documentation you can see that to upload a file to a bucket you need to create object first using:
const blob = bucket.file(yourFileName);
Then using createWriteStream you can upload the file

TypeError: storage._handleFile is not a function

I want to retrieve an image from the mongodb database using nodejs and mongoose as a ORM. I got this error when i was trying to retreive image from database. I have used multer-gridfs-storage for storing the image to mongodb
Hard to tell but you're probably using:
{ storage: { storage: diskStorage(...) }}
It should be
{ storage: diskStorage(...) }
Just a little developer tip mate, using multer-gridfs-storage you can upload the whole image into the data base . That means the database will be very heavy in a little time. So let's say after a quite a long time you will need to make a backup. So the backup time will be massive mate.
So my recommendation is that you use multer - npm. Just multer because using that you can still upload the image but not to the database. Instead you can store the image into your server by creating a dedicated folder for all your image and upload all incoming images there. To reference the image into a certain object, you can store the image name instead of the whole image. Thus the database size will be not increased rapidly

Upload filestream to cloud-files with Node.js

I know that it's possible to upload files to my cloud-files account in Node.js, using the following module: node-cloudfiles.
But is it also possible to upload a filestream directly?
In my case I am dowloading an image from a certain location in Node.js and want to upload this directly to my cloud-files account without saving the image temporary on my server.
Of course it is possible - you can just read the documentation on Rackspace Cloud Files API ( http://docs.rackspacecloud.com/files/api/cf-devguide-latest.pdf ) and implement the necessary parts yourself.
However, I'd suggest to wait until https://github.com/nodejitsu/node-cloudfiles/pull/11 gets integrated into the trunk - then node-cloudfiles library will support uploading files using streams so you won't have to create files before uploading.

Resources