-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extra params don't seem to be sent #12
Comments
I realized I forgot to post my code. This excerpt applies to this issue: Client:function process_files(e,delivery){
var file = e.target.files[0];
var b = document.body;
if(b.getAttribute("data-album")){
mrI = b.getAttribute('data-album');
}
else {
mrI = -1;
}
delivery.send(file, {loc:b.getAttribute("data-lat")+"|"+b.getAttribute("data-long"),mI:mrI});
e.preventDefault();
}
socket.on('connect',function(){
var delivery = new Delivery(socket);
delivery.on('delivery.connect',function(delivery){
document.getElementById('photoInput').addEventListener("change", function(e) {
process_files(e,delivery);
});
document.getElementById('audioInput').addEventListener("change", function(e) {
process_files(e,delivery);
});
document.getElementById('videoInput').addEventListener("change", function(e) {
process_files(e,delivery);
});
});
delivery.on('send.success',function(fileUID){
console.log("file was successfully sent.");
});
}); Server:delivery.on('receive.success',function(file){
console.log("FILE: "+ JSON.stringify(Object.keys(file),null,2)); // no property "params" here
// The code to fetch file.params was alternatively put over here, with no avail:
/*
var extraParams = file.params;
console.log(JSON.stringify(extraParams,null,2));
var mI = extraParams.mI;
*/
fs.writeFile(__dirname + "/public/media/"+file.name,file.buffer, function(err){
if(err){
console.log('File could not be saved. '+ err);
}
else{
var extraParams = file.params;
console.log(JSON.stringify(extraParams,null,2)); // returns undefined
var mI = extraParams.mI; // throws error, as property 'mI' of undefined can't be read
files.push({
src:file.name,
loc:extraParams.loc,
time:(new Date()).getTime(),
mI: mI
});
console.log(JSON.stringify(files));
sc = Object.keys(io.nsps["/"].adapter.rooms);
console.log("rooms: "+JSON.stringify(sc,null,2));
us = Object.keys(users);
console.log("user IDs: "+JSON.stringify(us,null,2));
data = fetchGroupData(sc,us);
socket.emit('invite_channel','{"type":"welcomeBackUpdate","cList":' +data.cn +',"rID":' +data.cid +',"locs":' +data.locs +',"times":' +data.times+'}');
console.log('File saved.');
}
});
}); |
I think I resolved the problem. Over at This code is what I am talking about: function FilePackage(file,receiving,params){
console.log("Params (received by FilePackage): "+JSON.stringify(params,null,2));
this.name = file.name;
this.size = file.size;
_this = this;
if(receiving){
this.uid = file.uid;
this.isText = file.isText;
this.mimeType = file.mimeType;
this.data = file.data;
this.dataURLPrefix = file.prefix;
this.params = file.params;
pubSub.publish('receive.success',this);
}else{
//Sending a file.
this.params = params;
console.log("Params (this.params, filePackage): "+JSON.stringify(this.params,null,2));
this.uid = this.getUID();
this.reader = new FileReader();
this.reader.onerror = function(obj){};
this.reader.onload = function(){
_this.base64Data = _this.reader.result;
_this.prepBatch();
};
this.reader.readAsDataURL(file);
};
};
function FilePackage(file,receiving,params){
console.log("Params (received by FilePackage): "+JSON.stringify(params,null,2));
this.name = file.name;
this.size = file.size;
// _this = this; --> assigned too early
if(receiving){
this.uid = file.uid;
this.isText = file.isText;
this.mimeType = file.mimeType;
this.data = file.data;
this.dataURLPrefix = file.prefix;
this.params = file.params;
_this = this; // includes all information from this
pubSub.publish('receive.success',this);
}else{
//Sending a file.
this.params = params;
console.log("Params (this.params, filePackage): "+JSON.stringify(this.params,null,2));
this.uid = this.getUID();
this.reader = new FileReader();
this.reader.onerror = function(obj){};
this.reader.onload = function(){
_this.base64Data = _this.reader.result;
_this.prepBatch();
};
_this = this; // includes all information from this
this.reader.readAsDataURL(file);
};
}; |
@JeroenRood
The code above is for the FilePackage object, I think you're looking at the file object. Different events return different object types. I haven't looked at this code in years unfortunately, so I can't offer too much more help. Have you thought about using something like |
Please update npm package. This package have older code when github |
Hi there, Is there any workaround for this issue? I could not fix it with the above suggestions. |
@piyusharora420 just copy delivery from github. In npm package stored old code I think.
Now all works, in server side you can get params by this way: in front-end you can use this: |
Thanks a lot @WilixLead. It fixed the issue. |
So far, Delivery.js has amazed me when it comes to simplicity of sending files through Socket.io. Props for making such a module! :-)
When I use
delivery.send(file,extraParams)
(extraParams being an object, as described in the readme), and I check the content offile
on the server afterreceive.succes
, I don't see the propertyparams
(I usedObject.keys()
to retrieve all the keys from thefile
-object), and readingfile.params
returns undefined.I'd like to send meta-data with my application. Do you have an idea how I can include this meta data (or params) after all? I tried altering
Delivery.prototype.send
,FilePackage
andFilePackage.prototype.prepBatch
; but with no avail so far. Could you give me a pointer for fixing this, or help me out here?Thanks in advance for taking a look at it!
The text was updated successfully, but these errors were encountered: