user8931142
user8931142

Reputation:

how to upload a file in meteor using ostrio files?

I am working on meteor application.How can I loop to all files instead of one file in profile template.I have successfully uploaded files.But when I fetch according to documentation then it only fetch only one image.And how can I change the directory of upload?? My profile.js file is:

imageFile:function() {
        return Images.findOne();
      }

My profile.html:

<img src="{{imageFile.link}}" alt="{{imageFile.name}}" />

How can I add image info to other database??

Upvotes: 1

Views: 537

Answers (1)

Jankapunkt
Jankapunkt

Reputation: 8413

There are a few things to consider when using this package.

But when I fetch according to documentation then it only fetch only one image.

  1. Your code is returning a cursor to a single file, using findOne. In order to fetch all files you should use find:
imageFiles() {
    return Images.find();
}
{{#each imageFiles}}
    <img src="{{this.link}}" alt="{{this.name}}" />
{{/each}}

This is basic template work and you should read more about it in the Blaze documentation.

  1. Images (I assume you followed the Wiki instructions) is not a Mongo.Collection but a FilesCollection. If you want the underlying Mongo. Collection you should reference it via Images.collection.

And how can I change the directory of upload??

  1. To change paths you should check your options, that you pass to the constructor, especially storagePath and downloadRoute.

How can I add image info to other database??

I assume that you mean that external means on another server or app instance. In this case you need to create a Collection, that uses the Mongo external Driver. How to do that is already answered here.

Just make sure, that you have also access to the public directory and that this collection is a collection that stores Files.

You might ask how to access the FilesCollection from this collection:

const ExternalImages = new FilesCollection({
  collectionName: 'nameOfExternalCollection',
});

Upvotes: 2

Related Questions