-
Notifications
You must be signed in to change notification settings - Fork 0
/
file-uploader.js
87 lines (69 loc) · 2.08 KB
/
file-uploader.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
var Minio = require("minio");
var amqp = require("amqplib/callback_api");
// var AMQP = require("./rabbit");
const mClient = new Minio.Client({
endPoint: "play.min.io",
port: 9000,
useSSL: true,
accessKey: "Q3AM3UQ867SPQQA43P2F",
secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG",
});
var file = "./Outgoing/example.pdf";
var testBucket,
testObject = "testObject",
testUrl;
var queue = "minio";
mClient.listBuckets(function (e, buckets) {
if (e) return console.log(e);
testBucket = buckets[0];
console.log("The first item of bucket list is found.");
console.log(testBucket);
var metaData = {
"Content-Type": "application/ootet-stream",
"X-Amz-Meta-Testing": 123,
example: 456,
};
mClient.fPutObject(
testBucket.name,
testObject,
file,
metaData,
function (err, etag) {
if (err) return console.log(err);
console.log("Upload the file successfully.");
mClient.presignedGetObject(
testBucket.name,
testObject,
1000,
function (e, presignedUrl) {
if (e) return console.log(e);
testUrl = presignedUrl;
console.log("Got the Url:");
console.log(testUrl);
amqp.connect("amqp://localhost", function (error0, connection) {
if (error0) {
throw error0;
}
console.log("Connected to the local RabbitMQ Server.");
connection.createChannel(function (error1, channel) {
if (error1) {
throw error1;
}
console.log("Create the channel to send a message into queue.");
const msg = testUrl;
channel.assertQueue(queue, {
durable: false,
});
channel.sendToQueue(queue, Buffer.from(msg));
console.log(" [x] Sent %s", msg);
});
// setTimeout(function() {
// connection.close();
// process.exit(0)
// }, 500);
});
}
);
}
);
});