Coder Social home page Coder Social logo

Comments (6)

raymondfeng avatar raymondfeng commented on June 14, 2024

The LoopBack mongodb connector doesn’t support gridfs out of box. But you can use the mongodb driver api.

For example,

var db = app.myDataSource.connector.db;

var gridStore = new GridStore(db, null, "w");
gridStore.open(function(err, gridStore) {
gridStore.write("hello world!", function(err, gridStore) {
gridStore.close(function(err, result) {

// Let's read the file using object Id
GridStore.read(db, result._id, function(err, data) {
  test.equal('hello world!', data);
  db.close();
  test.done();
});

});
});

Thanks,


Raymond Feng
Co-Founder and Architect @ StrongLoop, Inc.

StrongLoop http://strongloop.com/ makes it easy to develop APIs http://strongloop.com/mobile-application-development/loopback/ in Node, plus get DevOps capabilities http://strongloop.com/node-js-performance/strongops/ like monitoring, debugging and clustering.

On Dec 20, 2014, at 8:42 AM, Maker Su [email protected] wrote:

How to save file to gridfs as below for example?
Thank you very much.

def save(inputStream, contentType, originalFilename) {
def inputFile = gridFS.createFile(inputStream)
String extension = originalFilename.split('.')[-1]
String gridFSFilename=inputFile.id.toString() + '.' + extension
inputFile.setFilename(gridFSFilename)
inputFile.save()
return inputFile.filename
}

Reply to this email directly or view it on GitHub #73.

from loopback-connector-mongodb.

makersu avatar makersu commented on June 14, 2024

Thank you for hint.

from loopback-connector-mongodb.

makersu avatar makersu commented on June 14, 2024

When I try to run the sample,it returned:

TypeError: Cannot read property 'GridStore' of undefined 

So, I npm install mongodb and var GridStore = require('mongodb').GridStore,then I got:

TypeError: Cannot read property 'w' of undefined

Any help will be appreciated.Thanks.

from loopback-connector-mongodb.

makersu avatar makersu commented on June 14, 2024

My solution:

var db = app.datasources.db.connector.db;
db.safe = {w: 1};

var gridStore = new GridStore(db, null, "w");
  gridStore.open(function(err, gridStore) {
  ...
...

from loopback-connector-mongodb.

paulJordaan avatar paulJordaan commented on June 14, 2024

When trying this example with:

var db = app.datasources.db.connector.db;

It returns with with db as undefined.

Any suggestions?

from loopback-connector-mongodb.

superkhau avatar superkhau commented on June 14, 2024

Closing as resolved. @paulJordaan @makersu does var db = app.myDataSource.connector.db; work? Ping and I will reopen this issue if you still more information.

from loopback-connector-mongodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.