how to pipe an upload file to another server - sails.js

I have two server. server1 will recieve upload request from user and pipe that request to server2 to upload file to server2. Here is my code for server1
upload: function (req, res) {
console.log(req.headers);
console.log(req.body);
req.pipe(request.post('http://localhost:1337/file/upload')).pipe(res);
}
and here is code for server2:
upload: function (req, res) {
console.log(req.allParams());
console.log(req.file());
console.log(req.headers);
if (req.file("mot")) {
req.file('mot').upload({
dirname: require('path').resolve(sails.config.appPath, 'data')
}, function (err, data) {
if (err) {
console.log(err);
return res.json({
failed: true
});
} else {
console.log("file uploaded");
return res.ok();
}
}
)
}else{
}
}
when is use postman to send upload request directly to server2 it work. but when i send request to server1 i got this error on server2:
{ Error: ETIMEOUT: An Upstream (`mot`) timed out waiting for file(s). No files were sent after waiting 10000ms.
at Timeout.<anonymous> (/media/thanhtv/Data/bitbucket/nodejs/test/node_modules/skipper/standalone/Upstream/Upstream.js:62:15)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
code: 'ETIMEOUT',
message:
'ETIMEOUT: An Upstream (`mot`) timed out waiting for file(s). No files were sent after waiting 10000ms.' }
please help me out. i'm using sails.

Related

Has anyone successfully utilized IPPS for socket printing in Python or JS?

I can successfully socket print what I need with both via IPP, but can find no documentation on it being done securely via IPPS. Does anyone know if it's even possible?
Code:
var ipp = require("ipp");
var printer = ipp.Printer("https://printer.example.com:443/ipp/print");
var msg = {
"operation-attributes-tag": {
"requesting-user-name": "Bill Raley",
"document-format": "image/pwg-raster",
"requested-attributes": ["printer-description", "job-template",
"media-col-database"]
}
};
printer.execute("Get-Printer-Attributes", msg, function(err, res) {
console.log(err);
console.log(res);
});
Error:
{ Error: unable to verify the first certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1055:34)
at TLSSocket.emit (events.js:198:13)
at TLSSocket._finishInit (_tls_wrap.js:633:8) code:
'UNABLE_TO_VERIFY_LEAF_SIGNATURE' }

Http failure response for (unknown url): 0 Unknown Error","error":{"isTrusted":true}}

I have on my logs this error which I tried to reproduce with different devices but I have never been able to.
{“headers”:{“normalizedNames”:{},“lazyUpdate”:null,“headers”:{}},“status”:0,“statusText”:“Unknown Error”,“url”:null,“ok”:false,“name”:“HttpErrorResponse”,“message”:“Http failure response for (unknown url): 0 Unknown Error”,“error”:{“isTrusted”:true}}
This error comes from this function which calls to google api:
return new Promise((resolve, reject) => {
this.http
.post(
“https://automl.googleapis.com/v1beta1/projects/XXXXX/locations/us-central1/models/XXXXXXXXXX:predict”,
file,
{
headers: {“Authorization”:"Bearer "+accessToken}
}
)
.timeout(600000)
.map(res => res)
.toPromise()
.then(
//call then instead of subscribe to form the promise chain.
data => {
resolve(data);
},
err => {
reject(err);
this.utilsService.registerEvent(err,userId,version)
}
);
});
}
I don’t know how to solve it and how can reproduce it. It is generating 10 or 15 errors a day. Can anybody help me? Thanks!

How can I access both AWS Elasticache(Redis) and AWS EC2 (MongoDB) from same lambda function?

I can access separately but I cannot connect both of theese services.(AWS Elasticache(Redis) and AWS EC2 (MongoDB)). I tried theese: EC2, Elasticache and Lambda in same security group in AWS VPC. Also tried EC2 and Elasticache in different security group AWS VPC and lambda has these security groups. But didn't change anything. I used serverless framework 1.0. These connections in localhost redis and EC2(MongoDB) worked together succesfully. When I was writing to console serverless deploy, these operations did'nt work. Postman error is: 502 Bad Gateway.
{
"message": "Internal server error"
}
Here it is(I can connect to redis succesfully):
var client = redis.createClient(config.cache.connection.port, config.cache.connection.endpoint);
client.on("error", function (err) {
if(err){
console.log("Error: Redis connection was failed");
}else{
console.log("Success: Redis connection was established");
}
});
client.set("FEED10", "feed", redis.print);
client.get("FEED10", function(err, data){
if(err){
console.log("Error: ", err);
}
console.log("DATA: ", data);
client.quit();
});
Here it is(ı can connect to mongodb succesfully)
var options = {
user: config.database.connection.user,
pass: config.database.connection.password,
promiseLibrary: require('bluebird')
}
mongoose.connect(config.database.connection.endpoint, options, function(error) {
// Check error in initial connection. There is no 2nd param to the callback.
if(error){
console.log("Error: MongoDB connection was failed");
}
else{
console.log("Success: MongoDB connection was established");
}
});
Here it is(i can connect MongoDB but con not redis). Any ideas?
var options = {
user: config.database.connection.user,
pass: config.database.connection.password,
promiseLibrary: require('bluebird')
}
mongoose.connect(config.database.connection.endpoint, options, function(error) {
// Check error in initial connection. There is no 2nd param to the callback.
if(error){
console.log("Error: MongoDB connection was failed");
}
else{
console.log("Success: MongoDB connection was established");
}
});
var client = redis.createClient(config.cache.connection.port, config.cache.connection.endpoint);
client.on("error", function (err) {
if(err){
console.log("Error: Redis connection was failed");
}else{
console.log("Success: Redis connection was established");
}
});
client.set("FEED10", "feed", redis.print);
client.get("FEED10", function(err, data){
if(err){
console.log("Error: ", err);
}
console.log("DATA: ", data);
client.quit();
});

Auth0 custom database mongodb, signup script is returning SandboxTimeoutError

I'm trying to use my own mongo database which is created in mlab in auth0 for user management. Here is the template they provided.
function create (user, callback) {
mongo('mongodb://user:pass#mymongoserver.com/my-db', function (db) {
var users = db.collection('users');
users.findOne({ email: user.email }, function (err, withSameMail) {
if (err) return callback(err);
if (withSameMail) return callback(new Error('the user already exists'));
bcrypt.hashSync(user.password, 10, function (err, hash) {
if (err) { return callback(err); }
user.password = hash;
users.insert(user, function (err, inserted) {
if (err) return callback(err);
callback(null);
});
});
});
});
}
After changing connection URI, I tried to "create" a user by providing email and password with the script. I see the following error:
[SandboxTimeoutError] Script execution did not complete within 20 seconds. Are you calling the callback function?
I followed the Debug Script they provided. Here is the log:
$ wt logs -p "myservice-eu-logs"
[12:35:27.137Z] INFO wt: connected to streaming logs (container=myservice)
[12:35:29.993Z] INFO wt: new webtask request 1478435731301.992259
[12:35:30.047Z] INFO wt: { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
[12:35:30.047Z] INFO wt: js-bson: Failed to load c++ bson extension, using pure JS version
[12:36:05.080Z] INFO wt: finished webtask request 1478435731301.992259 with HTTP 500 in 35096ms
Any suggestions?
Actually, bcrypt.hashSync is a synchronous method, so the callback function is never called and the script times out.
Either use:
var hashedPwd = bcrypt.hashSync(user.password);
or
bcrypt.hash(user.password,10,function(....);

web page does not receive data from mongodb

I am a beginner.
I installed Bitnami MEAN stack and I have a question.
"[]" shows on the web page when I enter http://127.0.0.1:3000/tableList.
I want to know why the web page does not show the data in collections.
On Command Prompt:
C:\Bitnami\meanstack-3.2.3-1\test>SET DEBUG=test:* & npm start
test#0.0.0 start C:\Bitnami\meanstack-3.2.3-1\test
node ./bin/www
test:server Listening on port 3000 +0ms
connection successful
[]
GET /tableList 304 30.004 ms - -
GET /favicon.ico 200 7.164 ms - 1183
On mongodb.log file:
2016-04-05T00:08:04.350+0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:52192 #6 (4 connections now open)
2016-04-05T00:08:04.513+0700 I ACCESS [conn6] Successfully authenticated as principal chai on khamoo
On app.js file:
var mongoose = require('mongoose');
mongoose.connect('mongodb://chai:chai#localhost/khamoo', function(err) {
if(err) {
console.log('connection error', err);
} else {
console.log('connection successful');
}
});
mongoose.model('tableList',{tid: String});
app.get('/tableList', function(req, res) {
mongoose.model('tableList').find(function(err,tableList){
console.log(tableList);
res.json(tableList);
});
});