Maybe a beginner's question: get uploaded images on dev mode

Hi,

I’m a little frustrated because it took a very long time to get file upload working. I’m working with vue on the frontend and using meteor for backend. The file-upload is done using Meteor-Files from VeliovGroup. The uploading works without issues and the files are getting stored in the .meteor-Directory while the app is running in dev mode. But now, how can I get the images or other files I uploaded? The path that is stored in the FileCollection for each file is not right, if I use it for example for the src-attribute of an image. Is there something I’m missing? Is it simply not possible at dev mode?

Thanks a lot in advance. If you need specific code snippets, just ask :slight_smile:

Mario

I haven’t used that VG package, but I see in its docs that the storage path for uploaded files is .meteor/local/build/programs/server. The client can’t see that directory, nor can the server reliably fetch things from there. What’s more, the dev server will wipe them on server boot/build.

The simplest solution would be to store them in myAppDir/public/, or a subdir of that.

Alternatively, you could store them in the private assets folder, but then the server will need extra code to fetch them and serve them to a client. See https://docs.meteor.com/api/assets.html.

Finally, you can store them in a 3rd-party cloud, like AWS S3, and then use the public URL for client access. This is closer to best practice, because the file is separated from your Meteor server, which is nice for a few reasons; for one: if you have multiple instances of your Meteor server running (say, on Galaxy), this is the only way to go. It looks like VG has some pre-made solution for this.

When you say “path”, do you mean file path on disk, or a uri where the file can be accessed from a client?

How are you generating the uri for src?

The docs say you generate a link using the .link() method on a file object or using the {{fileURL }} helper in Blaze

It doesn’t matter if I take the path-attribute of a document of my FileCollection, or the link() funktion. The problem is, that I can’t get the images. They are stored temporarily in the runtime folders of meteor and it’s not possible to set another (different to the runtime-folder) path in the config of meteor-files.

config.storagePath doesn’t work? Did you contact VG?

it does work, but all i set will be under the .meteor-folder. so for example if i set storagePath to ‘uploads/images’ then the path in the app-folder is AppFolder/.meteor/local/build/programs/server/uploads/images and even a absolute path doesn’t work. The thing is, that I can’t get outside the .meteor folder. And if the images are stored in the build-folder i can’t get them to the frontend…

Update: it work’s when the app is deployed. But i have to get it working in dev mode…

it 100% should work in dev mode with the default and images should be served to the front end.

The biggest issue with the defaults in dev mode is that the files are lost on a fresh build.

You can set the set the storagePath outside the build directory by using an absolute path or using path traversal, kinda like this:

storagePath = path.normalize(Meteor.absolutePath + '/../MEDIA');

Thank you guys! I took the wrong absolute path for the config.storagePath. Now it works with the right absolute path. I still can’t access uploaded files in dev, that have been uploaded to the relative path in the temporary build-folder. But I think, I can do a workaround for that.