Meteor-files: Get GeoJson File as Object

Created on 19 Dec 2018  路  7Comments  路  Source: veliovgroup/Meteor-Files

Dear Team,

Loved to use use your package so far. I found myself with a GeoJson problem.

I use a regular form to upload a GeoJson file. No big deal. Problem is to get this file and use it to generate the map on _Leaflet_.

Template.mapDropdown.events({
    "change #mapFilesDropDown": function(event, template){
         event.preventDefault();
         console.log(event.target.value);
         var mapId = event.target.value;
         var myMap = Maps.findOne(mapId);
         console.log(myMap.path);
    }
});

This event get the File _id to return the selected GeoJson file. MyMap.path gives me the absolute path (assets/app/uploads/Maps/dnHkQkceumTKmLGSR.geojson), but I cant reach it...

How do I get the GeoJson file as a Json Object?, and use this object to generate my leaflet map? (this one is on me :D )

.link() question

All 7 comments

Hello @fillipefeitosa ,

Glad to hear you've found a use in our package 馃槂
Please use .link() method to get "downloadable" URL to uploaded file. Let me know if this method will work for you.

Thanks for the fast response!!

.link() gave me:

http://localhost:3000/cdn/storage/Maps/dnHkQkceumTKmLGSR/original/dnHkQkceumTKmLGSR.geojson

I am on development env. Am I supposed to use that on production?
Thanks again

@fillipefeitosa yes 馃憤

Sorry for the stupid question...

But how would I test the functionality to retrieve the file and parse the JSON before launch to production?

@fillipefeitosa usually it's done with running alpha/beta/staging stages.

I solved by setting a downloadRoute


export const Maps = new FilesCollection({
    collectionName: 'Maps',
    allowClientCode: true,
    downloadRoute: '/public/',

    onBeforeUpload(file){
        if(file.size <= 10485760 && /json|geojson/i.test(file.extension)){
            return true;
        }
        return 'Favor fazer upload de geojson v谩lido';
    }
});

Thanks for your time and great work,

Great @fillipefeitosa ,

I'm glad this one is solved quickly.
Please, keep in mind downloadRoute just a "fence" route, unless FilesCollection is initiated with public option.

Feel free to close it in case if the issue is solved on your end.

Was this page helpful?
0 / 5 - 0 ratings