Multi File Upload

2
Hi, I uderstand that the fielmanger will not allow multiple files to be loaded at once. I was wondering if there is and alternative? Could I upload the files to my server using ftp on a schduled basis and then in someway allocate each file to a corresponding mendix object. Hope that makes sense? Regards
asked
5 answers
3

Yes, you can do that.

You need to set up a constant within your modeler, then write a microflow that goes to the constant location retrieves your files and places them into your application.

You will need to configure the .m2eec file on your server to define the constant.

answered
1

Another way you could achieve something similar without using FTP, is to instruct the user to first put all the files he wants to upload in a ZIP achive and upload that (single) file using the standard Mendix file upload widget. With a little bit of Java code in your Mendix project, you can then easily extract the ZIP file into multiple Mendix FileDocument objects.

The advantage is you don't need an FTP server, nor do the users need an FTP client. They do need to know how to create ZIP files however. Both this solution and the FTP solution need some Java code on the server side, but nothing fancy (you only need to use the Mendix API and a few core Java classes; ZIP support is standard available in Java, see here).

answered
0

Thank you for that.

I have worked out how to create a constant, I think! I guess this just contains the filepath.

The bit I don't understand is the m2eec side of things, currenlty I'm running this locaally on my PC do I need to define the constant still in this way?

Thanks for all your help.

nick

answered
0

What you need to do is set up a scheduled that runs, say every 5 minutes. That scheduled action then calls a java action which lists all files in the specified directory (I would hardcode the path at first, worry about constants and specific locations later when you're deploying to a server).

Then, based on each file in your directory, call Core.saveFiledocument with the file (it needs an inputstream, so you'll have to construct that first from the file). Note that you have to create a mendixobject of type "filedocument" first to be able to save it using core.savefiledocument.

After that simply delete the file and you should be done!

answered
0

Hi not a java man, tried this but won't compile!

File folder = new File(uploadeddocuments);
    for(File file : folder.listFiles()) {           

    FileInputStream inputStream = new FileInputStream(file);
    Core.storeFileDocumentContent(IContext context,IMendixObject fileDocument, InputStream inputStream);
    }

It's probalby rubbish so any help gladly accepted!

answered