-
Notifications
You must be signed in to change notification settings - Fork 85
/
uploads.js
145 lines (128 loc) · 2.98 KB
/
uploads.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const { VK } = require('vk-io');
const fetch = require('node-fetch');
const fs = require('fs');
const vk = new VK({
token: process.env.TOKEN
});
/**
* Sets custom uploadUrl or timeout
*/
vk.upload.photoAlbum({
source: {
// uploadUrl: '<custom upload url>',
// timeout: 60e3,
values: [
// Examples of parameters below
{
value: '<value>'
}
]
}
});
/**
* Uploads photo for wall
*
* Auto filename and contentType
*/
Promise.all([
/* File path */
vk.upload.wallPhoto({
source: {
value: './path/to/cat1.jpg'
}
}),
/* File stream */
vk.upload.wallPhoto({
source: {
value: fs.createReadStream('./path/to/cat2.jpg')
}
}),
/* Buffer */
vk.upload.wallPhoto({
source: {
value: fs.readFileSync('./path/to/cat3.jpg')
}
}),
/* URL */
vk.upload.wallPhoto({
source: {
value: 'http://lorempixel.com/400/200/cats/'
}
}),
/* URL Buffer */
fetch('http://lorempixel.com/400/200/cats/')
.then(response => response.buffer())
.then(buffer => (
vk.upload.wallPhoto({
source: {
value: buffer
}
})
)),
/* URL Stream */
fetch('http://lorempixel.com/400/200/cats/')
.then(response => (
vk.upload.wallPhoto({
source: {
value: response.body,
contentLength: response.headers.get('content-length')
}
})
))
]);
/**
* Uploads photo for wall with contentType and filename
*/
Promise.all([
/* File path */
vk.upload.wallPhoto({
// jpeg at dat file
source: {
values: {
value: './path/to/cat1.dat',
contentType: 'image/jpeg',
filename: 'cat1.jpg'
}
}
}),
/* File stream */
vk.upload.wallPhoto({
// png at file without extensions
source: {
values: {
value: fs.createReadStream('./path/to/cat2'),
contentType: 'image/png',
filename: 'cat2.png'
}
}
})
// ...etc
]);
/**
* Uploads multiple files (current only photoAlbum)
*/
vk.upload.photoAlbum({
source: {
timeout: 1e3 * 60,
values: [
{
value: './path/to/cat1.jpg'
},
{
value: 'http://lorempixel.com/400/200/cats/'
},
{
value: fs.createReadStream('./path/to/cat2.jpg')
},
{
value: fs.createReadStream('./path/to/cat2.jpg'),
filename: 'cat2.jpg'
},
{
value: './path/to/cat5.dat',
contentType: 'image/jpeg',
filename: 'cat5.jpg'
}
]
}
});