-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
59 lines (36 loc) · 1.22 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
//const mime = require('mime');
const { Storage } = require('@google-cloud/storage');
var formidable = require('formidable');
const keyFilename="./uploadfilestonode-firebase-adminsdk-vifhf-80404ec328.json"; //replace this with api key file
const projectId = "uploadfilestonode" //replace with your project id
const bucketName = "uploadfilestonode.appspot.com";
const storage = new Storage({
projectId,
keyFilename
});
const bucket = storage.bucket(bucketName);
/* <input type="file" [formControl]="profImg"/> */
const filePath = './mountains.jpg';
const uploadTo = '' +filePath;
//const fileMime = mime.lookup(filePath);
bucket.upload(filePath,{
destination:uploadTo,
public:true,
metadata: {contentType: 'image/jpeg',cacheControl: "public, max-age=300"}
}, function(err, file) {
if(err)
{
console.log(err);
return;
}
console.log(createPublicFileURL(uploadTo));
});
function createPublicFileURL(storageName) {
return `http://storage.googleapis.com/${bucketName}/${encodeURIComponent(storageName)}`;
}
app.listen(3000, function() {
console.log("Server running 3000");
});