1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    27
    Vote Rating
    0
    dissectcode is on a distinguished road

      0  

    Default Open any type of file.

    Open any type of file.


    Hello. I need to open files from Extjs. I know I can use the window.open method but will it open *any* type of file like MS Word docs, and jpeg, and pdf etc? What should my approach be? thanks!!

    I am using Extjs 3 and servlets from Java code. I wanted to just return the file + file path and open it from Extjs.

    Oh, I need to open a pop-up. thank you

    I tried this:
    Code:
    new Ext.Window(
    {
          title: 'CMS File Preview',
          height: 400,
          width: 600,
           bodyCfg: {
                  tag: 'iframe',
                  src: '/Library/Tomcat/apache-tomcat-6.0.35/temp/uploads/env.sh',
                  style: 'border: 0 none'
           }
    }).show();
    but i get a 404 error but :

    Code:
    ls -l /Library/Tomcat/apache-tomcat-6.0.35/temp/uploads/env.sh
    -rw-r--r--  1  admin  504 Aug  8 09:05 /Library/Tomcat/apache-tomcat-6.0.35/temp/uploads/env.sh
    so the file exists


    I also tried this:

    Code:
    window.open('/Library/Tomcat/apache-tomcat-6.0.35/temp/uploads/env.sh');
    also not found.

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,927
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    This is usually handled by the browser plugins to open the supported documents.
    Most handle PDF, <image>.

    There is open document in browser of registered types. Search M$ KB

    As far as _any_ type, that is a tall order. The format has to be supported to be opened.
    ExtJS is not meant to be a JS document viewer.

    Scott.

  3. #3
    Sencha User
    Join Date
    Jul 2012
    Posts
    27
    Vote Rating
    0
    dissectcode is on a distinguished road

      0  

    Default


    so i'm just trying a text file. i have a servlet sending back the file with this :

    Code:
    response.setContentType( contentType );
    response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
    
    
    PrintWriter out = response.getWriter();
            
    FileInputStream fileToDownload = new FileInputStream(filePath);
            
    int c = 0;
    int totBytes = 0;
    while( (c=fileToDownload.read()) != -1 )
    {
                totBytes += c;
                out.write(c);
    }
            
            
    out.flush();
    out.close();
    fileToDownload.close();
    
    }

    and the response in :

    Code:
    Ext.Ajax.request(
                {
                    url: "/ctkb-spring/cmsFilePreview",
                    method: 'GET',
                    waitMsg: 'Getting File for Preview...',
                       success: function(response, opts)
                       {
                        //var obj = Ext.decode(response.responseText);
                          alert("success text = " + response.responseText.toSource()); 
    }
    });
    shows the file contents but how do i display it? thank you. i'm new. what do i do with the response in Extjs? (3)

  4. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,927
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    You can display text in a window like:

    Code:
    Ext.onReady(function() {
    	myPanel = Ext.create('Ext.Panel', {
    		width: 300,
    		height: 100,
    		title: 'Title',
    		layout: 'vbox',
    		frame: true,
    		renderTo: Ext.getBody(),
    		items: [
    			{
    				xtype: 'button',
    				text: 'Click to open TEXT window',
    				handler: function(b, e) {
    					var myWin = Ext.create("Ext.window.Window", {
    						title: 'HTML Window',
    						modal: true,
    						html: '<iframe src="../../extjs4/license.txt" width="100%" height="100%" ></iframe>',
    						width: 700,
    						height: 500
    					});
    					myWin.show();
    				}
    			}
    		]
    	});
    });
    Scott.

  5. #5
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,927
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Here is a goof reference for opening a PDF:
    http://ext4all.com/post/extjs-3-show-pdf-in-a-panel

    Scott.

  6. #6
    Sencha User
    Join Date
    Jul 2012
    Posts
    27
    Vote Rating
    0
    dissectcode is on a distinguished road

      0  

    Default


    My file is returned in the POST response from a call to a servlet's doGet(). How do I get it from the response in the button's handler and display it?

    The file is saved on the server, and I need to display it on the client, who has no knowledge of the server filesystem.

    Code:
    var previewButton = {
            text: 'Preview File',
            fieldLabel: fieldLabelStr,
            id: nameStr,
            xtype: 'button',
            target: '_blank',     // ??? trying these out
            hrefTarget: '_blank',
            handler: function (btn)
            {
                
                Ext.Ajax.request(
                {
                    url: "/filePreview",
                    method: 'GET',
                    waitMsg: 'Getting File for Preview...',
                       success: function(response, opts)
                       {
                        //var obj = Ext.decode(response.responseText);
                          alert("success text = " + response.responseText.toSource()); 
                          
                          alert("response headers = " + response.getAllResponseHeaders() );
                    }
    });
    
    }

  7. #7
    Sencha User
    Join Date
    Jul 2012
    Posts
    27
    Vote Rating
    0
    dissectcode is on a distinguished road

      0  

    Default


    The example in the link is awesome and clean, but how to I replace "src" property with what is returned by a POST call? (I posted that Java servlet code above)

    thank you

  8. #8
    Sencha User
    Join Date
    Jul 2012
    Posts
    27
    Vote Rating
    0
    dissectcode is on a distinguished road

      0  

    Default


    By the way: I keep reading all I have to do in the servlet is set the Content Disposition header to this and it will "pop up automatically" :

    Code:
    response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
    
    
    but nothing pops up in my POST Ext.Ajax.request ?? Which is why I'm stuck and asking. thanks

  9. #9
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,927
    Vote Rating
    443
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Correct ... you can send the header content like such: XLS example:

    Code:
    // sending headers to force the user to download the file
    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: inline;attachment;filename="'.$filename.'.xls"');
    // open downloaded file
    Code:
    Ext.Ajax.request({
        method: 'POST',
        url: 'index.php/table_export/export_table/',
        success: function(xhr) {
            // clear mask and display
            grid_panel.getEl().unmask();
            window.open('xls/' + report_name + '.xls');
        },
        failure: function() {
            // clear mask
            grid_panel.getEl().unmask();
            alert('AJAX ERROR: Unable to export report, please contact support');
        }
    });
    Scott.

  10. #10
    Sencha User
    Join Date
    Jul 2012
    Posts
    27
    Vote Rating
    0
    dissectcode is on a distinguished road

      0  

    Default


    Thank you. Now I understand. I also found this to be helpful :
    http://www.cleancode.co.nz/blog/195/...-file-download

Thread Participants: 1

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi