Comments (9)
I think the Meteor._lastSessionId
value is stored in the x-mtok
cookie, which you can use to get the connection from Meteor.connection
or Meteor.server
(I'm not 100% sure which one of both you have to look into).
from meteor-files.
how i can get connection info at server side
@Kaczkazniszczenia please elaborate what hook/callback you're talking about, and what exactly are you trying to accomplish?
from meteor-files.
@Kaczkazniszczenia post your code as well, let's speak code please
from meteor-files.
const Files = new FileCollection({
collectionName: 'files',
allowClientCode: false,
...
onAfterUpload: function (file) {
const userId = this.userId; // not important for example
const userIp = this.connection?.clientAddress; <--- example of what i need
console.log(`uploaded by user:${userId} from ${userIp}`);
return createAfterUpdate(imageBucket).call(this, file);
},
onAfterRemove: function (file) {
const userId = this.userId; // not important for example
const userIp = this.connection?.clientAddress <---- example of what i need
console.log(`Removed by user:${userId} from ${userIp}`);
}
});
@dr-dimitru
My main objectives are to get info on users ( IP is a must ) who are uploading and removing files, so i imagine onAfterUpload
and onAfterRemove
would be perfect place to log their actions.
While we are at it, it would be nice to have user connection info on all hooks (onBeforeUpload, protected, ...).
This is just an example and I will be happy and grateful as long as there is secure way to get user IP, somewhere in pipeline while uploading,
I think the Meteor._lastSessionId value is stored in the x-mtok cookie, which you can use to get the connection from Meteor.connection or Meteor.server (I'm not 100% sure which one of both you have to look into).
@jankapunkt Might get messy/not secure if users start logging on multiple computers or do something malicious. Anyway this is a fine idea i'm sure to explore if i wont be able to get/put connection info in to FileCollection methods. Big thx.
edited formmating
from meteor-files.
@Kaczkazniszczenia onAfterUpload
and onAfterRemove
and other hooks/callbacks are state-less by nature. I recommend to:
- use
.onLogin
to fetch user's current session and IP - Update user's object with up-do date details
- Find user's object in Meteor-File's hooks/callback and use user's details as needed
from meteor-files.
@Kaczkazniszczenia have you figured it out?
from meteor-files.
Still working on it, but I decided to create token before file upload and place them inside file meta.
On server side token will be matched with session info allowing me to fetch it after upload.
@dr-dimitru would you like me to put my code here after I'm done ?
from meteor-files.
Thanks for help.
from meteor-files.
@Kaczkazniszczenia not sure how token related to obtaining user's IP from you original question. Please share code, I'm curious
from meteor-files.
Related Issues (20)
- [FilesCollection.ServiceFile] Path "/assets/app/uploads/ServiceFileCollection" is not writable! HOT 2
- How to change item metadata before it is inserted into the collection? HOT 9
- How do I update a filesCollection after Server side Write created? HOT 1
- Since Meteor 2.11 - Exception in setTimeout callback: TypeError: fs.remove is not a function HOT 9
- Question: Can you store directly in GridFS? HOT 2
- Question: Save link in database?
- Update aws-sdk to v3 in 'Use AWS:S3 As Storage' Documentation HOT 4
- Files.load -> options.fileName is not in filepath HOT 2
- FilesCollection.find(...).each() not working properly? HOT 1
- HTTP uploads not working, multi-instance/cluster environment NGINX balanced HOT 5
- onAfterUpload not throwing error in uploader.on('end') HOT 5
- Cannot stream a video with filenames longer than 80 characters HOT 1
- wrong custom error message when using HTTP
- Make Meteor-Files compatible with meteor-desktop? HOT 4
- Uncaught error when uploading an empty file
- Help Wanted: Method '_FilesCollectionAbort_attachments' not found [404] HOT 1
- Match error: Unknown key in field HOT 5
- User can not be determined in protected callback in Firefox HOT 5
- [3.0.0-beta.6] fileObj._id on upload end ?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meteor-files.