Just like it says on the title, i need to get the complete path for a file that a user will upload. The user will be upload an actual file not giving a download link and I intend on using said path to then upload it to a different location via cURL script.
Thanks
1 Like
Not possible, this is not a Bonita issue but a web/browser standard. I’ve researched this and found no way of doing it. It’s a security thing.
What you have to do is get the user to upload the file using file widget, then save the internal file to a Tomcat Directory (i.e tomcat/webapps/mycompany/tempfiles/fileXYZ.docx), then do the cURL script using this temporary path and file. Because this is a valid tomcat directory - it can be accessed with ease - you can use the path to the file.
That’s the only way I know of, and it works with no problem,
regards
Seán
I’m stuck on this problem for a few days trying different approaches and solutions and I was thinking that uploading to the internally to the server first was the only option.
Does bonita support this? From what I can tell with the file widget it saved to the database
Yes and no, you are right that the document is saved to the process instance (case) but this can be deleted as part of the process reducing the size of the archive database but before you do, save the file to disk…
You would have to use a writer to the directory you choose i.e. tomcat/webapps/mycompany/tempfiles code such as
//for java 7+
import java.nio.file;
String tomcatDirYouWantToSaveToo = get the tomcatDirEtc.;
byte bytes = myDocumentVariable.getContent(); //something like that…
Path path = Paths.get(tomcatDirYouWantToSaveToo +“"+myfilename+”.pdf");
Files.write(path, bytes);
Then call your system script connector to do your cURL, and if OK not forgetting to delete the file so your server doesn’t fill up
regards
Ah!
Why didn’t you say you were using OpenKM before? There are Bonita Connectors for OpenKM…could make your life a little easier, or you could use REST to upload the byte file to it. There are examples of this using Nuxeo.
For OpenKM see here…, here… , here(video) .
If this is not what you want to do…need more explanation.
regards
PS - well done on returning a success/fail code. You have no idea how many people ignore this…
Unfortunatly OpenKM connectors were not working for me, the create directories and the download (2 of the 3 features that I needed) were working perfectly, unfortunatly the upload was iffy and it would stop working after a few uploads and it caused some sort of problem that made other connectors not work as well (the boolean return was actually null, not false/true).
Although I did try to figure out the problem I just ended up moving on to ownCloud as I was sort of required to test more than one.
One thing I was not very fond of was the state of the documentation for OpenKM, it was all over the place and sort of lacking.
Anyways, problem solved, thanks for the help
Although I havent done the cURL call I can now upload files into my VM and I feel the uploading to ownCloud using cURL is only a trivial matter. Anyways this is the code I’ve used:
import java.io.*;
try {
def path = System.getProperty(“catalina.home”) //destination of the file to be uploaded
path += “/” + field_File1.getFileName() //file name, make sure to include extension (using file_Field already yields it, but it’s useful to keep it in mind if you want another name
FileOutputStream fos = new FileOutputStream(path)
fos.write(field_File1.getContent())
fos.flush()
fos.close();
} catch (Exception e) {
return e.toString()
}
return “ok!”
//the script returns a string, i’m not using it for anything except for debugging as I was testing it
I can’t describe how I’m feeling right now I’ve been cracking my head the last days trying my luck with OpenKM which unfortunatly wasn’t being cooperative and using alfresco was not an option