-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle-drive-spica-function.js
More file actions
55 lines (47 loc) · 1.34 KB
/
Copy pathgoogle-drive-spica-function.js
File metadata and controls
55 lines (47 loc) · 1.34 KB
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
50
51
52
53
54
55
// Dependencies: googleapis@^108.0.0 - https@^1.0.0
import http from 'https';
import { google } from 'googleapis';
const SCOPES = 'https://www.googleapis.com/auth/drive';
const FILE_NAME = 'file name';
const PARENT_ID = '< PARENT ID >';
const fileUrl = '< FILE URL >';
const auth = new google.auth.GoogleAuth({
credentials: {
"type": "",
"project_id": "",
"private_key_id": "",
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url": ""
},
scopes: SCOPES
});
export default async function (req, res) {
http.get(fileUrl, async (resultData) => {
const driveServices = google.drive({ version: 'v3', auth });
let fileMetaData = {
'name': FILE_NAME,
'parents': [PARENT_ID]
}
let media = {
body: resultData
}
let response = await driveServices.files.create({
resource: fileMetaData,
media: media,
fields: 'id'
});
switch (response.status) {
case 200:
console.log('Google Drive ID:', response.data.id);
break;
}
}).on('error', (err) => {
console.log("http error")
});
return {}
}