{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback-example-remote/issues/4","labels_url":"https://api.github.com/repos/strongloop/loopback-example-remote/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback-example-remote/issues/4/comments","events_url":"https://api.github.com/repos/strongloop/loopback-example-remote/issues/4/events","html_url":"https://github.com/strongloop/loopback-example-remote/issues/4","id":99544560,"number":4,"title":"How to invoke loopback-component-storage remotely? ","user":{"login":"pulkitsinghal","id":821963,"avatar_url":"https://avatars.githubusercontent.com/u/821963?v=3","gravatar_id":"","url":"https://api.github.com/users/pulkitsinghal","html_url":"https://github.com/pulkitsinghal","followers_url":"https://api.github.com/users/pulkitsinghal/followers","following_url":"https://api.github.com/users/pulkitsinghal/following{/other_user}","gists_url":"https://api.github.com/users/pulkitsinghal/gists{/gist_id}","starred_url":"https://api.github.com/users/pulkitsinghal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pulkitsinghal/subscriptions","organizations_url":"https://api.github.com/users/pulkitsinghal/orgs","repos_url":"https://api.github.com/users/pulkitsinghal/repos","events_url":"https://api.github.com/users/pulkitsinghal/events{/privacy}","received_events_url":"https://api.github.com/users/pulkitsinghal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-06T23:24:02Z","updated_at":"2015-08-10T14:20:19Z","closed_at":null,"body":"I'm trying to figure out a way to get a node worker process to download a file that was uploaded to another loopback server that host the main website ... for fetching & processing so that the worker may do the deed.\r\n\r\nIn the worker which uses the client/remoteDS ... If I add the following to the `model-config.json` file:\r\n```\r\n  \"container\": {\r\n    \"dataSource\": \"storage\"\r\n  }\r\n```\r\n\r\nInside `model-config.json`\r\n```\r\n{\r\n  \"_meta\": {\r\n    \"sources\": [\r\n      \"loopback/common/models\",\r\n      \"loopback/server/models\",\r\n      \"../common/models\"\r\n    ]\r\n  },\r\n  \"container\": {\r\n    \"dataSource\": \"remoteDS\"\r\n  }\r\n}\r\n```\r\n\r\nFile Structure:\r\n```\r\n├── client\r\n│   ├── config.json\r\n│   ├── datasources.json\r\n│   ├── loopback.js\r\n│   ├── middleware.json\r\n│   ├── model-config.json\r\n│   └── package.json\r\n├── common\r\n│   └── models\r\n│       ├── container.js\r\n│       └── container.json\r\n```\r\n\r\nI try to invoke a download method with syntax like:\r\n```\r\nclient.models.Container.getContainers(function(){\r\n    console.log(arguments);\r\n});\r\n```\r\n\r\nI'm experimenting by pointing my node worker to download from a locally running instance of: `loopback-component-storage/example-2.0` but I really haven't gotten anywhere yet.\r\n\r\n```\r\n  loopback:app use final:after  errorHandler +0ms\r\n[TypeError: Object function ModelConstructor(data, options) {\r\n      if (!(this instanceof ModelConstructor)) {\r\n        return new ModelConstructor(data, options);\r\n      }\r\n      if (ModelClass.settings.unresolved) {\r\n        throw new Error('Model ' + ModelClass.modelName + ' is not defined.');\r\n      }\r\n      ModelBaseClass.apply(this, arguments);\r\n    } has no method 'getContainers']\r\n```"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback-example-remote/issues/comments/129470744","html_url":"https://github.com/strongloop/loopback-example-remote/issues/4#issuecomment-129470744","issue_url":"https://api.github.com/repos/strongloop/loopback-example-remote/issues/4","id":129470744,"user":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars.githubusercontent.com/u/1140553?v=3","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"created_at":"2015-08-10T14:20:19Z","updated_at":"2015-08-10T14:20:19Z","body":"IMO, there are two factors involved here.\r\n\r\nFirst of all, \"remote\" connectors requires remoting metadata from the server model to be available in the client model too. loopback-component-storage does not support this use case yet, you have to manually copy remoting metadata from [StorageService](https://github.com/strongloop/loopback-component-storage/blob/2b0d9f693894de638de1a786b2d646d6b789a9b3/lib/storage-service.js#L255-L327) to your client model. IIRC, the `Container` model provided by loopback-component-storage is the model which gets StorageService methods mixed in.\r\n\r\n```js\r\n// client/models/container.json\r\n{\r\n  \"name\": \"Container\",\r\n  \"methods\": {\r\n    \"getContainers\": {\r\n      \"isStatic\": true,\r\n      \"accepts\": [],\r\n      \"returns\": {arg: 'containers', type: 'array', root: true},\r\n      \"http\": {verb: 'get', path: '/'}\r\n    },\r\n    // etc.\r\n  }\r\n}\r\n```\r\n\r\nThis should allow you to call all containers methods that return regular JSON responses.\r\n\r\nSecondly, because strong-remoting does not support stream types on the server (see  strongloop/strong-remoting#35) and passes full `req` and `res` objects to the download/upload methods, the remote connector (strong-remoting client) does not have necessary information on how to build request and process response for these methods, or at least I believe so.\r\n\r\nThat means that you cannot download a file using remote connector at the moment. I believe this feature is doable, it's just not implemented yet.\r\n\r\nBTW the same issue affects AngularJS SDK - because the \"download\" method metadata does not say that a stream is returned, the SDK cannot generate an appropriate client method for downloading files."}}