I am trying to get attachments from incoming emails and store these in a table called “email_attachments”.
I am using the code below as part of the method that pick up the email. The code seems to run through the deugger fine.
However, O can’t get the attachment to upload into the table and the filesize keeps getting returned as 0. The emailid and the name of the file get added to the record without any problem.
The ‘attachment’ column in the tables is set up to accept Media files. I can’t see where I am going wrong. Can anybody point me in the right direction.
I have a relationship Document_ID_to_Media_fk_DocumentID and list all Attachments related to the current Document/Email on a Tab. Then attach following Method to the Attachments list.
I believe credit for the coding goes to Harjo from a Tip on Servoy Magazine
if ( me_filename) // check if filename exists
{
// Creates a temporary file (will be deleted after application shutdown)
// get the position of the last “.” in the file name
var a = me_filename.lastIndexOf(“.”)
var b = “temp”
//get the 3 letter extension - INCLUDING the “.”
var c = me_filename.substring(a)
//create a temporary file that will be auto-deleted by Servoy when client is exited
var filename = application.createTempFile(b,c)
//write the binary data out to disk at the temporary file location
application.writeFile(filename,me_blob);
//launch the document with external application
if(utils.stringMiddle(application.getOSName(),1,7) == “Windows”)
{
application.executeProgramInBackground(‘rundll32’, ‘url.dll,FileProtocolHandler’,filename)
}
else
{
application.executeProgram(‘open’, filename);
}
}
else
{
plugins.dialogs.showErrorDialog( ’ W a r n i n g ', ‘Action failed due to incomplete filename’ , ‘OK’)
}
Many thanks. I’ve found almost exactly the same thing searching through these forums. The only difference is this also allows for MACS. The forum message also provided another way for it to work with Linux - though this was less clear.
var filename = forms.email_attachments.filename // Get the name of the file
application.output (filename)
var a = filename.lastIndexOf(“.”)//returns the number from beginning of file name to the dot.
application.output (a)
var b = filename.substr(0,a) //returns the file name
application.output(b)
var c = filename.substring(a) //returns the file extension.
application.output(c)
var filename = application.createTempFile(b,c) // creates a temp file using the file name and extension
application.writeFile(filename,attachment);
So, on to my next question (more because I want to understand and learn the capabilities of Servoy then a real need) Once you’ve opened a file on the local machine, is there a way to make an ammendment to that file and save it back to the same record on the server automatically?