Meteor-files: Some questions about http upload

Created on 26 May 2017  ·  11Comments  ·  Source: veliovgroup/Meteor-Files

I have tried this sample:
https://gist.github.com/ankibalyan/bbd69e1b08645d61bc9f535afcd8a3a1

and get some questions....

  • I get this.userId === undefined here:
  WebApp.connectHandlers.use(_multerInstance.single('dp')).use("/api/v1/avatar/upload", Meteor.bindEnvironment(function(req, res, next) {
    if (req.file !== undefined && req.file.mimetype.substr(0, 6) == 'image/' && req.headers.authtoken.length) {
    console.log(this.userId);
...
}

And, I have tried pass Meteor.userId() from client, like this:

            const formData = new FormData();
            formData.append('dp', file);
            formData.append('userId', Meteor.userId());

but, It's not safe right?
I'm not sure why cant get this.userId, and what some suggestions...

  • Another question, after write, will call afterUpload or not...
    if not, where should I put s3 integration codes...
    maybe in write callback?
  Avatars.write(_readData, _addFileMeta, function write(_uploadError, _uploadData) {
    if (_uploadError) {
      console.log(_uploadError);
    }
    // here?
  }
question

Most helpful comment

@dr-dimitru

  • react-native can use JS/ES6 to build mobile app with native method, in both ios and android...
  • And yes, it can include other NPM packages, but not all
  • I haven't tried to use meteor-file package with react-native directly, since I don't think I can use global variable defined in meteor client...even with react-native-meteor
  • and swift is another programming language can build ios app, it was apple's programming language like object-c, so no JS/ES6

  • react-native may not enough to build a native app, so I may need swift either...

  • and then I think, upload from non-meteor, should be more suitable...

Thank you for your warmhearted!

All 11 comments

  1. .write() has fourth argument, set it to true to pass through afterUpload
  2. but, It's not safe right? - Right.
  3. Self-Managed WebApp.connectHandlers has no idea about the user - use Meteor.Methods instead

What are you actually trying to accomplish here?

@dr-dimitru
I want to upload image or audio or video from react native to meteor backend...
And also upload to s3 storage...
So...this should be the right way to get user info in webapp? just like https://gist.github.com/ankibalyan/bbd69e1b08645d61bc9f535afcd8a3a1

            const hashedToken = Accounts._hashLoginToken(params.query.authToken);
            const user = Meteor.users.findOne({ 'services.resume.loginTokens.hashedToken': hashedToken });

I haven't tried to use _hashLoginToken yet....
I will have a try...

So...this should be the right way to get user info in webapp?

Yes, if you set authtoken header.

But why not use build-in upload (.insert()) method?
If you having issue with http, try to use ddp transport.

@dr-dimitru
Do you mean I can use build-in upload insert with react native?
I have used react-native-meteor, but I dont konw how to use meteor-file build-in method with it...

I have seen this https://github.com/inProgress-team/react-native-meteor/issues/126
and this https://github.com/VeliovGroup/Meteor-Files/issues/271

and finally... I try to use webapp+multer...

I see no reason why this example wouldn't work - https://github.com/VeliovGroup/Meteor-Files/wiki/React-Example

In the #217 Upload from non-meteor was requested. Means there is no DDP/Meteor Methods

hello @dr-dimitru
I have seen example with react...
and, how could I get UserFiles, in react-native?
It should be the global variable defined in meteor...right?

  getMeteorData() {
    var handle = Meteor.subscribe('files.all');
    return {
      docsReadyYet: handle.ready(),
      docs: UserFiles.find().fetch() // Collection is UserFiles
    };
  },

I'm a little confused...

Yes, when I want to use meteor backend with swift...I think upload from non-meteor will be the only choice...

I'm not familiar with react-native nor swift.
As far as I'm see react-native-meteor brings DDP/Methods/Collections/etc.
If you can include other NPM packages into swift with react-native Meteor-Files package should work.
Can you execute JS/ES6 within swift?

@dr-dimitru

  • react-native can use JS/ES6 to build mobile app with native method, in both ios and android...
  • And yes, it can include other NPM packages, but not all
  • I haven't tried to use meteor-file package with react-native directly, since I don't think I can use global variable defined in meteor client...even with react-native-meteor
  • and swift is another programming language can build ios app, it was apple's programming language like object-c, so no JS/ES6

  • react-native may not enough to build a native app, so I may need swift either...

  • and then I think, upload from non-meteor, should be more suitable...

Thank you for your warmhearted!

Hi! @liu0fanyi have you tried https://www.npmjs.com/package/react-native-meteor#additionals-collection-methods ?

It seems that react-native-meteor can call collections directly. Maybe you can run the React Example from RN https://github.com/VeliovGroup/Meteor-Files/wiki/React-Example

If you need a complete course for Meteor+RN take a look at this one. I ended it and decided to use meteor for my project! http://learn.handlebarlabs.com/p/react-native-meteor
This course from the same dev is for free http://learn.handlebarlabs.com/p/react-native-basics-build-a-currency-converter

This one looks solid to me, going to close it.
Feel free to reopen it in case if the issue still persists on your end.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

menelike picture menelike  ·  3Comments

schlaegerz picture schlaegerz  ·  3Comments

RE-N-Y picture RE-N-Y  ·  3Comments

dr-dimitru picture dr-dimitru  ·  3Comments

sylido picture sylido  ·  3Comments