Reading files from a directory inside a meteor app

后端 未结 7 598
既然无缘
既然无缘 2021-01-04 08:28

How can i read the public directory in a meteor application inside my /server path.

I tried using the native \'fs\' package but i keep getting a file/di

相关标签:
7条回答
  • 2021-01-04 08:41

    This works for me in Meteor 1.0:

    var fs = Npm.require('fs')
    var xsd = fs.readFileSync(process.cwd().split('.meteor')[0] + 'server/company.xsd', 'utf8')
    
    0 讨论(0)
  • 2021-01-04 08:47

    This is no longer true. For Meteor 0.8, the folder "../client/app" is public. Thus, use fs.readdirSync('../client/app') to get files and folders in public.

    Source: personal experience and https://stackoverflow.com/a/18405793

    0 讨论(0)
  • 2021-01-04 08:52

    I learned that it is best to upload files in your private folder if you are not displaying them outside. In my case I need to store XML uploads and process them. At first I wrote the XML into the public folder but that would trigger a reload. Then I renamed the the upload folder to /public/.#uploads which would stop the reload of Meteor, but then again...it completely ignored that folder during build and the uploaded folder would not exist in the build (throw ENOENT error during read).

    So I figured out it is best to put the files in /private/files and then reading goes as follows:

    result = fs.readdirSync('assets/app/files')

    Everything in the private folder will be moved to the Assets folder where during runtime there is an APP folder available (you do not see that in your build folder structure).

    It helps to just simple dump result = fs.readdirSync('.') to see what folder you in and look through the structure.

    ***UPDATE***** Locally putting files in private folder still triggered meteor rebuild/update (perhaps not in production..) so I found another solution using the UploadServer just to define the upload directory: https://github.com/tomitrescak/meteor-uploads

    0 讨论(0)
  • 2021-01-04 08:52

    For Meteor 1.4, use server Assets. See the official docs on Assets http://docs.meteor.com/api/assets.html

    0 讨论(0)
  • 2021-01-04 08:54

    Access files without the "/public" part. In a running Meteor app, the public directory becomes your root, and everything that is located at /public/whatever can be accessed at /whatever.

    Additionally, if you're playing around with files, you might find these useful:

    • FileSaver.js
    • CollectionFS
    0 讨论(0)
  • 2021-01-04 09:00

    For meteor 1.0.2 public is /web.browser/app/ Checked by entering .meteor dir Total path in linux /home/user/your_app_name/.meteor/local/build/programs/web.browser/app/ And to get to root is `process.env.PWD or process.cwd(). Im not sure if its work deployed.

    _meteor_bootstrap_.serverDir +'/assets/app'
    

    This is path to private folder.

    0 讨论(0)
提交回复
热议问题