-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdropbox-upload.js
53 lines (43 loc) · 1.22 KB
/
dropbox-upload.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
/*
* Sample usage with dropbox storage
* dependencies: dropbox, express, express-form-post
*/
const express = require("express");
const app = express();
const path = require("path");
const efp = require("express-form-post");
const formPost = efp({
store: "dropbox",
filename: function(req, file, cb) {
cb(Date.now() + file.originalname);
},
api: {
accessToken: process.env.dropboxAccessToken
}
});
app.use(express.static(path.join(__dirname, "static")));
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.post("/upload", formPost.middleware(), (req, res, next) => {
console.log("I just received files", req.files);
res.send("Upload successful!");
});
/* the above code is equivalent to this
app.post("/upload", (req, res, next) => {
formPost.upload(req, res, () => {
console.log("I just received files", req.files);
res.send("Upload successful!");
});
});
*/
app.get("*", (req, res) => {
res.render("index");
});
app.use((req, res) => {
res.render("index");
console.log("req.files: ", req.files);
console.log("req.body: ", req.body);
});
app.listen(5000, () => {
console.log("Test server listening in on port 5000");
});