Topic
  • 9 replies
  • Latest Post - ‏2014-08-04T12:15:45Z by MGamboa
MGamboa
MGamboa
105 Posts

Pinned topic download file from PluginService

‏2014-01-31T17:05:06Z |

Is it possible to download a file from a plugin service using Request.invokePluginService?  The HttpServletResponse object is being loaded with the appropriate content data and the file data is being writen to the ServletOutputStream of the HttpServletResponse.

The following error is being returned to the ICN UI:

A connection to the web client cannot be established by user the following URl:..

This error can be caused by a configuration problem on the web application server or by a problem with the web client.
Try to log in again. If the problem persists, report this error to your system administrator.
The following error was returned: F_CreateTime,F_Locked,F_Overdue,Name,F_LockedUser
....<rest content for file>

I am using ICN 2.0.2

Thanks,

Martin

  • damorris
    damorris
    825 Posts

    Re: download file from PluginService

    ‏2014-02-03T12:53:59Z  

    There is a sample of getting content in the SamplePluginGetContentService class in the samplePlugin.

  • MGamboa
    MGamboa
    105 Posts

    Re: download file from PluginService

    ‏2014-02-03T15:39:26Z  
    • damorris
    • ‏2014-02-03T12:53:59Z

    There is a sample of getting content in the SamplePluginGetContentService class in the samplePlugin.

    I tried that logic.  In my case, it is a little different.  In the example it is associated with a viewer that is displaying the data.  In my case I am building data from logic, not from stored content.  And when it is sent to the client, it should be saved as a file causing to the browser to open the File Save dialog.  On the server I am using the following logic

    String fileName = "filename.csv";
    byte[] byteData = data.getBytes(); // data variable is a String object that contains the data to be stored in the file
    response.setContentType("application/octet-stream");
    response.setContentLength(byteData.length);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");

    InputStream is = new ByteArrayInputStream(byteData);
    OutputStream os = response.getOutputStream();
    transferData(is, os); // this is the method from the SamplePluginGetContentService transferData
    os.flush();
    os.close();

    Here is the Javascript that makes the service call

    var serviceParams = new Object();
                serviceParams.data = data;
                Request.invokePluginService("PluginId", "PlugServiceID",
                    {
                        requestParams: serviceParams
                    }
                );

    The error is still the one that I put in my first post on this thread.

    Thanks,

    Martin

     

  • MGamboa
    MGamboa
    105 Posts

    Re: download file from PluginService

    ‏2014-02-03T19:15:33Z  
    • damorris
    • ‏2014-02-03T12:53:59Z

    There is a sample of getting content in the SamplePluginGetContentService class in the samplePlugin.

    Also tried the following to be more like the example.  The call was received by the service, but the response didn't trigger browser File Save dialog.,

    var serviceParams = new Object();
                serviceParams.data = data
                xhr.post({
                    url: ecm.model.desktop.getServicesUrl() + "/plugin/
    PluginId/PlugServiceID/0",
                    handleAs: "json",
                    content: {
                        data: serviceParams.data
                    }
                });

  • HannesvanderWalt
    HannesvanderWalt
    2 Posts

    Re: download file from PluginService

    ‏2014-07-24T12:49:47Z  
    • MGamboa
    • ‏2014-02-03T19:15:33Z

    Also tried the following to be more like the example.  The call was received by the service, but the response didn't trigger browser File Save dialog.,

    var serviceParams = new Object();
                serviceParams.data = data
                xhr.post({
                    url: ecm.model.desktop.getServicesUrl() + "/plugin/
    PluginId/PlugServiceID/0",
                    handleAs: "json",
                    content: {
                        data: serviceParams.data
                    }
                });

    I need  to do exactly the same thing. Did you manage to resolve this?

  • MGamboa
    MGamboa
    105 Posts

    Re: download file from PluginService

    ‏2014-07-24T13:37:39Z  

    I need  to do exactly the same thing. Did you manage to resolve this?

    I did it with 2 services.  First service, PluginFileService takes in a POST of the file content and saves it to server file and responses with unique file name.  Second service, PluginDownloadService is called in an new browser window passing in unique file name, and services responses with file output stream.

    Here is some code from Second service

    byte[] byteData = data.toString().getBytes();
    response.reset();
    response.setContentType("application/x-download");
    response.setContentLength(byteData.length);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    ServletOutputStream outStream = response.getOutputStream();
    outStream.write(byteData);
    outStream.flush();
    outStream.close();

    Here is some code from JS file that makes call for download

    var serviceData = new Object();
    serviceData.data = fileContent;
    Request.postPluginService("Plugin", "PluginFileService", "application/x-www.form-urlencoded",
        {
            requestBody: serviceData.data,
            requestCompleteCallback: function(response) {    // success

                var exportUrl = ecm.model.desktop.getServicesUrl() +
                    "/plugin.do?plugin=Plugin&action=PluginDownloadService&exportFileName=" + response.data;

                exportUrl = Request.appendSecurityToken(exportUrl);
                
                window.open(exportUrl, "_blank");
            }
        }
    );

  • HannesvanderWalt
    HannesvanderWalt
    2 Posts

    Re: download file from PluginService

    ‏2014-07-24T13:58:27Z  
    • MGamboa
    • ‏2014-07-24T13:37:39Z

    I did it with 2 services.  First service, PluginFileService takes in a POST of the file content and saves it to server file and responses with unique file name.  Second service, PluginDownloadService is called in an new browser window passing in unique file name, and services responses with file output stream.

    Here is some code from Second service

    byte[] byteData = data.toString().getBytes();
    response.reset();
    response.setContentType("application/x-download");
    response.setContentLength(byteData.length);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    ServletOutputStream outStream = response.getOutputStream();
    outStream.write(byteData);
    outStream.flush();
    outStream.close();

    Here is some code from JS file that makes call for download

    var serviceData = new Object();
    serviceData.data = fileContent;
    Request.postPluginService("Plugin", "PluginFileService", "application/x-www.form-urlencoded",
        {
            requestBody: serviceData.data,
            requestCompleteCallback: function(response) {    // success

                var exportUrl = ecm.model.desktop.getServicesUrl() +
                    "/plugin.do?plugin=Plugin&action=PluginDownloadService&exportFileName=" + response.data;

                exportUrl = Request.appendSecurityToken(exportUrl);
                
                window.open(exportUrl, "_blank");
            }
        }
    );

    Thank you very much.

  • Ravi Teja
    Ravi Teja
    1 Post

    Re: download file from PluginService

    ‏2014-08-02T13:17:33Z  
    • MGamboa
    • ‏2014-07-24T13:37:39Z

    I did it with 2 services.  First service, PluginFileService takes in a POST of the file content and saves it to server file and responses with unique file name.  Second service, PluginDownloadService is called in an new browser window passing in unique file name, and services responses with file output stream.

    Here is some code from Second service

    byte[] byteData = data.toString().getBytes();
    response.reset();
    response.setContentType("application/x-download");
    response.setContentLength(byteData.length);
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
    ServletOutputStream outStream = response.getOutputStream();
    outStream.write(byteData);
    outStream.flush();
    outStream.close();

    Here is some code from JS file that makes call for download

    var serviceData = new Object();
    serviceData.data = fileContent;
    Request.postPluginService("Plugin", "PluginFileService", "application/x-www.form-urlencoded",
        {
            requestBody: serviceData.data,
            requestCompleteCallback: function(response) {    // success

                var exportUrl = ecm.model.desktop.getServicesUrl() +
                    "/plugin.do?plugin=Plugin&action=PluginDownloadService&exportFileName=" + response.data;

                exportUrl = Request.appendSecurityToken(exportUrl);
                
                window.open(exportUrl, "_blank");
            }
        }
    );

    Hi,

     i've tried this.but i am facing issue while using it in IE8 .I am getting the error as shown in the following screenshot.it is working once i click on the diagnosis connection problem.Please help me in this.

    Thanks in Advance

     

    Attachments

  • MGamboa
    MGamboa
    105 Posts

    Re: download file from PluginService

    ‏2014-08-04T12:15:32Z  

    Hi,

     i've tried this.but i am facing issue while using it in IE8 .I am getting the error as shown in the following screenshot.it is working once i click on the diagnosis connection problem.Please help me in this.

    Thanks in Advance

     

    I don't think this error has to do with your code.  It looks to be an environment or performance issue.  Is it taking some time for the download file to be generated and/or transferred to the browser?  The browser could be timing out.

    Click "More Information" on the error dialog and see if there is anything else that might explain the issue.

  • MGamboa
    MGamboa
    105 Posts

    Re: download file from PluginService

    ‏2014-08-04T12:15:45Z  

    Hi,

     i've tried this.but i am facing issue while using it in IE8 .I am getting the error as shown in the following screenshot.it is working once i click on the diagnosis connection problem.Please help me in this.

    Thanks in Advance

     

    I don't think this error has to do with your code.  It looks to be an environment or performance issue.  Is it taking some time for the download file to be generated and/or transferred to the browser?  The browser could be timing out.

    Click "More Information" on the error dialog and see if there is anything else that might explain the issue.