plugins.file.writeFile

Forum to discuss the Web client version of Servoy.

plugins.file.writeFile

Postby AlanBourke » Fri Sep 18, 2015 5:35 pm

What firewall ports need to be open for this to work?
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby mboegem » Fri Sep 18, 2015 9:30 pm

Hi Allen,

never had problems with this, so what are you trying to accomplish?
- smart/webclient
- local filesystem / write to remote filesystem
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: plugins.file.writeFile

Postby AlanBourke » Sat Sep 19, 2015 1:06 pm

Hi

Servoy 7.4.4, webclient only. Production environment has a Servoy solution on a Windows Server 2008 R2 accessed over the internet.

Just want to present a PDF for download in the normal way from the local filesystem on the web server using plugins.file.writeFile() as per every example out there. Nothing complicated. Works perfectly on my PC, works perfectly deployed on an Azure test server and accessed via the internet, works perfectly accessing it while on the production server desktop via RDP. When accessed as a normal user would, via a web browser hitting the production server external IP address, nothing happens, i.e. I don't get the browser's 'file save' dialog as I would expect. No Servoy errors logged, nothing.

This has been driving me insane for several years now - I changed it to email the PDF instead but it should work as a download, dammit!
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby patrick » Sat Sep 19, 2015 2:06 pm

Maybe the browser tries to open the PDF directly in a new tab and new tabs are blocked?

How exactly does your code snippet look like?
Patrick Ruhsert
Servoy DACH
patrick
 
Posts: 3703
Joined: Wed Jun 11, 2003 10:33 am
Location: Munich, Germany

Re: plugins.file.writeFile

Postby AlanBourke » Sun Sep 20, 2015 3:46 pm

Code is below. Works fine everywhere except it needs to, from any browser. It hits the 'PDF presented ...' log line no problem.

Code: Select all
/**
* Use built-in WriteFile() function to present a PDF for download or display
* depending on what the user's browser is set to do.
* @param {String} pdflocation
* @param {String} prefix 
* @properties={typeid:24,uuid:"8211D1E0-2E74-422B-9762-B1EF363C8772"}
*/
function downloadPDF(pdflocation, prefix)
{
   var attachmentFile = plugins.file.convertToJSFile(pdflocation);
   
   // -- Attempt to present the file to the browser.
   if (attachmentFile.exists())
   {
      var fbytes = plugins.file.readFile(pdflocation);
      plugins.file.writeFile(utils.stringTrim(prefix) + '.pdf', fbytes, 'application/pdf');
      plugins.Log.info('Presented ' + pdflocation + ' for download.');   
   }
   else
   {
      plugins.Log.warn('Download requested but ' + pdflocation + ' does not exist.');
   }
}
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby AlanBourke » Sun Sep 20, 2015 7:02 pm

If you look at the 5th post from the bottom in this thread: https://www.servoy.com/forum/viewtopic.php?f=34&t=19964&hilit=+download#p107621

To me that is strange - 192.168.1.7 is the LAN address of the server that Servoy is on, so why is it trying to use that to download the file from when I access it over the web?

Image
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby ROCLASI » Mon Sep 21, 2015 8:52 am

Hi Alan,

So it's a server error. What do you see in the servoy and tomcat logs?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: plugins.file.writeFile

Postby AlanBourke » Mon Sep 21, 2015 9:56 am

They don't show anything untoward.

The files that it is intended to download are not underneath the Servoy server directory, i.e. they are in another location on the disk. Would that mean permissions issues?

Servoy is in

Code: Select all
D:\servoy\


The PDFs are in (for example)

Code: Select all
D:\myapplication\pdf\a\testuser\
Last edited by AlanBourke on Mon Sep 21, 2015 10:30 am, edited 1 time in total.
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby mboegem » Mon Sep 21, 2015 10:28 am

Anything in the admin page referring to this local IP?
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: plugins.file.writeFile

Postby AlanBourke » Mon Sep 21, 2015 10:33 am

@Marc

Not that I can see.
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby mboegem » Mon Sep 21, 2015 11:20 am

So what's the internal address? I assume it's the local address of the cloud server you're using?
Marc Boegem
Solutiative / JBS Group, Partner
Servoy Specialist
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image
User avatar
mboegem
 
Posts: 1750
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

Re: plugins.file.writeFile

Postby ROCLASI » Mon Sep 21, 2015 11:38 am

Hi Alan,

I believe the trick is in turning the JSFile into a RemoteJSFile like so:
Code: Select all
function downloadPDF(pdflocation, prefix) {
    var attachmentFile = plugins.file.convertToJSFile(pdflocation);

    // -- Attempt to present the file to the browser.
    if (attachmentFile.exists()) {
        var fbytes = plugins.file.readFile(pdflocation);
        var _oFile = plugins.file.createTempFile(utils.stringTrim(prefix), '.pdf');
        _oFile = plugins.file.convertToRemoteJSFile(_oFile.getAbsolutePath());
        if (_oFile) {
            // this will trigger the download
            if (!plugins.file.writeFile(_oFile, fbytes, 'application/pdf')) {
                throw new Error("Error during writing of the pdf");
            }
            // clean up after us
            _oFile.deleteFile();
        }
        plugins.Log.info('Presented ' + pdflocation + ' for download.');   
    } else {
        plugins.Log.warn('Download requested but ' + pdflocation + ' does not exist.');
    }
}


Hope this helps.
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: plugins.file.writeFile

Postby AlanBourke » Mon Sep 21, 2015 3:50 pm

I'll give that a shot, many thanks.
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby AlanBourke » Tue Sep 22, 2015 10:28 am

The code above fails on:

Code: Select all
_oFile = plugins.file.convertToRemoteJSFile(_oFile.getAbsolutePath());


because getAbsolutePath() returns:

Code: Select all
C:\Users\abourke\AppData\Local\Temp\ref 14890999597871051031.pdf


but

Code: Select all
Exception Object: java.lang.IllegalArgumentException: Remote path should start with '/'
MSG: Remote path should start with '/'
Remote path should start with '/'
Wrapped java.lang.IllegalArgumentException: Remote path should start with '/'
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Re: plugins.file.writeFile

Postby AlanBourke » Tue Sep 22, 2015 11:29 am

OK I've amended it to rewrite the path in a *nix style (removed drive letters, changed slashes to forward slashes), it works here so will test live.
-------------------------------------------------------------------------------------------
Servoy SAN Developer
User avatar
AlanBourke
 
Posts: 198
Joined: Tue Aug 02, 2011 3:32 pm
Location: Dublin, Ireland

Next

Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 4 guests