-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtestapi.js
More file actions
20 lines (16 loc) · 700 Bytes
/
Copy pathtestapi.js
File metadata and controls
20 lines (16 loc) · 700 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const request = require('request');
const fs = require('fs');
const path = require('path');
// const API_URL = 'http://localhost:4000/file'; // Local EndPoint
const API_URL = 'https://morejust.herokuapp.com/file';
var r = request.post(API_URL, function optionalCallback (err, httpResp, fileLink) {
if (err) {
return console.error('Upload failed:', err);
}
console.log('Upload successful! Link:', fileLink);
});
var form = r.form();
// To load file from current folder
form.append('file', fs.createReadStream(path.join(__dirname, 'image.png')));
// To load file anywhere from computer
// form.append('file', fs.createReadStream('/Users/viktorkirillov/Documents/GitHub/store/image.png'));