1.0.10 • Published 6 years ago
freeupload v1.0.10
Free File Uploader 🌱
Free upload is a package for uploading & keeping image to google-cloud/storage via firebase without charge or adding credit card.
Note: Need some firebase credentials and Google cloud credential.
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
$ npm i freeupload
Usages
const express = require("express");
const bodyParser = require("body-parser");
const freeUpload = require("freeupload");
const Multer = require('multer');
const keyFilename = 'serviceaccount.json'; //keep the file (downloaded from google cloud service account) in your ptojects root directory and replace the serviceaccount.json with the filename
const bucketName = 'projectId.appspot.com'; // replace projectId with your firebase project Id
const projectId = "projectId"; // replace projectId with your firebase project Id
const app = express();
const multer = Multer ({
storage: Multer.memoryStorage (),
limits: {
fileSize: 5 * 1024 * 1024, // no larger than 5mb, you can change as needed.
},
});
//Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.post (
'/upload',
multer.single ('file'),
async (req, res) => {
let file = req.file;
if (file) {
try{
let url = await freeUpload.upload (file, keyFilename , bucketName, projectId);
res.json(url);
}
catch(err){
}
}
}
);
const port = process.env.PORT || 8085;
app.listen(port, () =>
console.log(`Server Running On Port ${port}`)
);
Firebase credentailas manage
##Steps Go to firebase console
1
2
3
4
5
6
7
8
9
Google cloud credentailas manage
##Steps