Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Working Example of File Download?

    Hello,

    Can anyone point me to a working example of file download functionality? I've found all kinds of suggestions, things that should work, recommendations on using servlets, the SmartGWT fileDownload mechanism, etc.

    I've tried all kinds of things, but to no avail.

    All I'm looking to do is:
    1. Send a list of file names to the server as Criteria
    2. Create a zip of those files on the server
    3. Present the user with a Save As dialog for the zip file

    #1 and #2 are no problem. Works great.

    How do I accomplish #3?

    Thanks a lot.

    #2
    Look at the Upload / Download sample folder in the EE Showcase.

    Comment


      #3
      Need clarification on how to download a file

      Originally posted by Isomorphic View Post
      Look at the Upload / Download sample folder in the EE Showcase.
      Could you please clarify what specific documentation you’re referring to.

      I found two examples in the EE Showcase. The first was downloading an .xlsx file from a ListGrid and the second was downloading a file in conjunction with a data source (“Custom Download”).

      I would simply like to make a call (RPC or whatever) from the client, pass a little information, and cause a file to be downloaded. Can you please point me to the documentation on how to do this.

      Comment


        #4
        The second example you refer to ("Custom Download") seems to show exactly this.

        Can you clarify - what aspect is still confusing after looking over the code for this sample?

        Comment


          #5
          Operation type 'fetch' not supported by this DataSource

          Originally posted by Isomorphic View Post
          The second example you refer to ("Custom Download") seems to show exactly this.

          Can you clarify - what aspect is still confusing after looking over the code for this sample?
          The example in the EE showcase has a ListGrid connected to a data source.

          I would like to download a file independent of a database table or a ListGrid.

          I created a minimal application which stripped out references to a table or a ListGrid.

          From the sample code when I execute this Java statement:

          Code:
          dsResponse = dsRequest.execute();
          I get this error:

          Code:
          java.lang.Exception: Operation type 'fetch' not supported by this DataSource (download)
          Here is the client side code:

          Code:
          DynamicForm form = new DynamicForm();
          
          // Button to invoke the download
          
          ButtonItem download = new ButtonItem("download", "Download File");
          		
          // Click handler for the download button
          		
          download.addClickHandler(new ClickHandler() {
          
          	@Override
          	public void onClick(ClickEvent event) {
          		DataSource ds = DataSource.get("download";);  
          		DSRequest dsRequest = new DSRequest();  
          		dsRequest.setOperationId("download";);  
          		dsRequest.setDownloadResult(true); 
          		dsRequest.setDownloadToNewWindow(true);
          		ds.fetchData(new Criteria(), null, dsRequest);
          	}
          });
          
          form.setItems(download);
          form.draw();
          Here is the server side code:

          Code:
          public class Downloader {
          	
          	 public void downloadData(DSRequest dsRequest, RPCManager rpc)  
          	    {  
          	        DSResponse dsResponse = new DSResponse();  
          	        try {  
          	            rpc.doCustomResponse();  
          	            HttpServletResponse response = rpc.getContext().response;  
          	            response.setHeader("content-disposition", "attachment; filename=download.txt");   
          	            response.setContentType("text/plain");  
          	            dsResponse = dsRequest.execute();  // THIS CAUSES AN EXCEPTION!!!
          	            ServletOutputStream out = response.getOutputStream();  
          	            out.write("this is downloaded data\r\n\r\n".getBytes()); 
          	            out.flush();
          	            out.close();
          	            dsResponse.setStatus(DSResponse.STATUS_SUCCESS);  
          	            rpc.send(dsRequest, dsResponse);  
          	        } catch (Exception e) {  
          	            try {  
          	                rpc.sendFailure(dsRequest, e.getMessage());  
          	            } catch(Exception er) {}  
          	        }  
          	    }  
          
          }
          Here is the data source xml file:

          Code:
          <DataSource ID="download" serverType="generic" >
          	<operationBindings>
          		<binding operationId="download" operationType="fetch"
          			serverMethod="downloadData">
          			<serverObject lookupStyle="new"
          				className="com.cedarcone.MVP1.server.samples.Downloader" />
          		</binding>
          	</operationBindings>
          </DataSource>
          Here is the console after the download button is pushed:

          Code:
          === 2013-05-24 19:30:36,856 [l0-0] INFO  RequestContext - URL: '/MVP1/sc/IDACall', User-Agent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0': Moz (Gecko) with Accept-Encoding header
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Host:127.0.0.1:8888
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Accept-Language:en-US,en;q=0.5
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Accept-Encoding:gzip, deflate
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Referer:http://127.0.0.1:8888/MVP1.html?gwt.codesvr=127.0.0.1:9997
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Cookie:isc_cState=ready; JSESSIONID=1bmam849e98g2
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Connection:keep-alive
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Content-Type:application/x-www-form-urlencoded
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - Header Name:Value pair: Content-Length:1276
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - session exists: null
          === 2013-05-24 19:30:36,870 [l0-0] DEBUG IDACall - remote user: null
          === 2013-05-24 19:30:36,885 [l0-0] DEBUG XML - Parsed XML from (in memory stream): 1ms
          === 2013-05-24 19:30:36,888 [l0-0] DEBUG XML - Parsed XML from __USE_CONTAINER__/MVP1/sc/system/schema/List.ds.xml: 1ms
          === 2013-05-24 19:30:36,893 [l0-0] DEBUG RPCManager - Processing 1 requests.
          === 2013-05-24 19:30:36,903 [l0-0] DEBUG RPCManager - Request #1 (DSRequest) payload: {
              criteria:{
              },
              operationConfig:{
                  dataSource:"download",
                  operationType:"fetch"
              },
              appID:"builtinApplication",
              operation:"download",
              oldValues:{
              }
          }
          === 2013-05-24 19:30:36,906 [l0-0] INFO  IDACall - Performing 1 operation(s)
          === 2013-05-24 19:30:36,906 [l0-0] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
          === 2013-05-24 19:30:36,906 [l0-0] DEBUG DeclarativeSecurity - DataSource download is not in the pre-checked list, processing...
          === 2013-05-24 19:30:36,918 [l0-0] INFO  ProxyHttpServletResponse - content-disposition set to: attachment; filename=download.txt - unwrapping response output stream (CompressionFilter)
          MVP1: samples.Downloader: before execute
          === 2013-05-24 19:30:36,918 [l0-0] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
          === 2013-05-24 19:30:36,918 [l0-0] DEBUG DeclarativeSecurity - DataSource download is not in the pre-checked list, processing...
          === 2013-05-24 19:30:36,918 [l0-0] DEBUG AppBase - [builtinApplication.download] No userTypes defined, allowing anyone access to all operations for this application
          === 2013-05-24 19:30:36,919 [l0-0] DEBUG AppBase - [builtinApplication.download] No public zero-argument method named '_download' found, performing generic datasource operation
          MVP1: samples.Downloader: server side failure: java.lang.Exception: Operation type 'fetch' not supported by this DataSource (download)
          java.lang.Exception: Operation type 'fetch' not supported by this DataSource (download)
          	at com.isomorphic.datasource.DataSource.notSupported(DataSource.java:2562)
          	at com.isomorphic.datasource.DataSource.executeFetch(DataSource.java:2484)
          	at com.isomorphic.datasource.DataSource.execute(DataSource.java:1367)
          	at com.isomorphic.application.AppBase.executeDefaultDSOperation(AppBase.java:726)
          	at com.isomorphic.application.AppBase.executeAppOperation(AppBase.java:658)
          	at com.isomorphic.application.AppBase.execute(AppBase.java:491)
          	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2033)
          	at com.cedarcone.MVP1.server.samples.Downloader.downloadData(Downloader.java:22)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
          	at java.lang.reflect.Method.invoke(Unknown Source)
          	at com.isomorphic.base.Reflection.adaptArgsAndInvoke(Reflection.java:972)
          	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:416)
          	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
          	at com.isomorphic.datasource.DSRequest.execute(DSRequest.java:2030)
          	at com.isomorphic.servlet.IDACall.handleDSRequest(IDACall.java:216)
          	at com.isomorphic.servlet.IDACall.processRPCTransaction(IDACall.java:173)
          	at com.isomorphic.servlet.IDACall.processRequest(IDACall.java:138)
          	at com.isomorphic.servlet.IDACall.doPost(IDACall.java:74)
          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
          	at com.isomorphic.servlet.BaseServlet.service(BaseServlet.java:152)
          	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
          	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
          	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1097)
          	at com.isomorphic.servlet.CompressionFilter.doFilter(CompressionFilter.java:259)
          	at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1088)
          	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
          	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
          	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
          	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
          	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
          	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
          	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
          	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
          	at org.mortbay.jetty.Server.handle(Server.java:324)
          	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
          	at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
          	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
          	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
          	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
          	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
          	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

          Comment


            #6
            fake unused database table needed?

            Originally posted by dbscott525 View Post
            I would like to download a file independent of a database table or a ListGrid.
            This is an update to the previous post. If I put in a table in the datasource xml file that I don’t use, the download works.

            Here is the updated datasource xml file:

            Code:
            <DataSource 
            	dbName="Mysql"
            	tableName="download"
            	ID="download"
            	dataSourceVersion="1"
            	generatedBy="v8.3p_2013-05-10/EVAL Deployment 2013-05-10"
            	serverType="sql"
            >
            	<fields>
            		<field primaryKey="true" name="ID" type="sequence"></field>
            	</fields>
            	
            	<operationBindings>
            		<binding operationId="download" operationType="fetch"
            			serverMethod="downloadData">
            			<serverObject lookupStyle="new"
            				className="com.cedarcone.MVP1.server.samples.Downloader" />
            		</binding>
            	</operationBindings>
            </DataSource>
            The table “download” is empty and not used for anything else.

            So is there a way to download a file without having to have the fake unused table in the database?

            Comment


              #7
              No, there is no need for a "fake" table. The example code uses dsRequest.execute() to execute a SQL query so that it can retrieve some data to use in putting together the custom download response.

              If you simply do not call dsRequest.execute(), there will be no SQL query and no need for a table.

              See the QuickStart Guide, Server Framework chapter, for more background about how to write DMIs and the purpose of dsRequest.execute().

              Comment


                #8
                File downloding

                I am working with isomorphic 8.0 and i have problem with file downloading.

                means i have created functionality for csv file downloading but i have problem. i got proper response from server but not file downloading popup open i have tried many things.

                I have read whole documention about downloading and use all possible attributes or methods but didn't success.

                I have added snap short of my response from server side.

                client side code:-

                click : function ()
                {

                var dsRequest = {
                ID: "dsRequest",
                operationId:"download",
                downloadResult:true,
                downloadToNewWindow: false,
                actionURL:context+"/rest/AdapterTree/download",


                };

                AdapterGroupDataSource.fetchData({"parentId":"Default"},null,dsRequest);
                }
                });


                I have added response snapshot.

                Please solve my problem

                Thanks
                Attached Files

                Comment

                Working...
                X