Simple export for attachments in database (pdf, doc, rtf...)

I have two fields in my table for attachments:

filedata (Media)
filename (text)

The filedata (Media) can contain .doc,.pdf, .htm, .rtf, or .txt.

I need a simple way for users to just click on a button to launch a save dialog box on either MAC or PC and have the attachment save the file to their hard drive.

Any ideas?

thanks,
David

Example solution would be greatly appreciated.

Servoy 3.1 on Windows 2003 Server

That’s fairly easy. See the file plugin for sample code.

// Shows a save file dialog, suggesting c:\ as default
var vFile = plugins.file.showFileSaveDialog('C:\' + filename);
if (!vFile) {
   // User canceled
   return;
}
var vSuccess = plugins.file.writeFile(vFile, filedata);
if (!vSuccess) {
   // something went wrong; probably a file with that name already exists
   // do something smart :-)
}
// maybe open the file?

Hope this helps!

That works for me. For some reason I thought I would have to test to verify which OS and set the path accordingly.

Just tested it on both MAC and PC works great.

thx,
David