jalik / meteor-jalik-ufs

Upload File System for Meteor **DISCONTINUED**
MIT License
100 stars 29 forks source link

How do I upload files on the server side #111

Closed loseangel1984 closed 7 years ago

loseangel1984 commented 7 years ago

hi, I'm in a directory on the server side has a file, how to use your development kit upload files to the Mongo?

jalik commented 7 years ago

https://github.com/jalik/jalik-ufs#importing-file-from-a-url-server

import {Mongo} from 'meteor/mongo';
import {UploadFS} from 'meteor/jalik:ufs';

const Photos = new Mongo.Collection('photos');

const PhotoStore = new UploadFS.store.Local({
    collection: Photos,
    name: 'photos',
    path: '/uploads/photos'
});

let url = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png';
let attr = { name: 'Google Logo', description: 'Logo from www.google.com' };

// You can import directly from the store instance
PhotoStore.importFromURL(url, attr, function (err, file) {
    if (err) {
        console.error(err.message);
    } else {
        console.log('Photo saved :', file);
    }
});

// Or using the common UFS method (requires the store name)
UploadFS.importFromURL(url, attr, storeName, callback);