• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

[SOLVED] Download .docx to the browser

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • [SOLVED] Download .docx to the browser

    I have an option where a user can request that their data be merged to create a word document with a .docx extension. My program generates the document with no problem. When I try to download the document to the user it sends it to the browser instead. I added the DOCX information to file VVFXQ100 per the API document.

    Here is my RPG code:
    Code:
             // Send file to the browser
    
             vvOut.download='Y';
             vvOut.file = %Char(Name) + '.docx';
             vvout.contentType='DOCX';
             vvout.binary='Y';
             vvOut_file(NewDoc:vvOut);
    Here is the function on the browser end for the call to the server.
    Code:
                    function fnMerge(submit){
                        if (submit === true) {
                            Ext.Ajax.request({
                                url: 'vvcall.pgm',
                                params: {
                                    action: 'mergeDocument',
                                    pgm: 'PRMSPTLIST',
                                    PMID: currentRecord.data.PMID,
                                    PEID: Ext.getCmp('DOCUMENT').getValue()
                                },
                                success: function(response){
                                    var check = response.responseText;
                                    if (check) {
                                        var data = Ext.util.JSON.decode(response.responseText);
                                        if (data.SUCCESS == '1') {
                                            Ext.get('mergeWindow').switchOff({
                                                duration: 1,
                                                callback: function(){
                                                    Ext.getCmp('mergeWindow').hide();
                                                    parent.showMessage('', '<b><center>Record Merged<\/b><\/center>');
                                                }
                                            });
                                        }
                                        else {
                                            Ext.getCmp(data.FLD).markInvalid(data.MSG);
                                            Ext.getCmp(data.FLD).focus();
                                        }
                                    }
                                },
                                failure: function(){
                                    Ext.getBody().unmask();
                                    Ext.Msg.alert('Failure', 'Failed to receive a response from server');
                                }
                            });
                        }
                        else {
                            currentRecord = Ext.getCmp('mainPRMSPTLISTGrid').getSelectionModel().getSelected();
                            Ext.getCmp('mergeWindow').show();
                        }
                    }
    Thanks in advance.

  • #2
    I almost have it. I changed my EXTJS code to the following when the user hits the Merge button.

    Code:
                    var MergeDocument = function(){
                        PMID = currentRecord.data.PMID;
                        PEID = Ext.getCmp('DOCUMENT').getValue()
                        Ext.DomHelper.append(document.body, {
                            tag: 'iframe',
                            frameBorder: 0,
                            width: 0,
                            height: 0,
                            css: 'display:none;visibility:hidden;height:1px;',
                            src: 'vvcall.pgm?sid=' + sid + '&opt=' + opt + '&pgm=prmsptlist&action=mergeDocument&PMID=' + PMID + '&PEID=' + PEID
                        });
                        Ext.getCmp('mergeWindow').hide();
                        parent.showMessage('', '<b><center>Record Merged<\/b><\/center>');
                         };
    It works except the name of the file vvcall.pgm instead of the file name I gave it in my program. If I open this file in word the information is correct. What do I need to change so that the file name is mydocument.docx

    Thanks in advance.

    Comment


    • #3
      I am using a time stamp to name my document. I change it to a hard coded "Test.docx" to see if it would make a difference. The result is the same. The file name is still vvcall.pgm.

      Comment


      • #4
        Can you debug or add a DSPLY command and see what values you are setting?

        What does %Char(Name) + '.docx'; actually resolve to?

        What does NewDoc equal?

        Comment


        • #5
          vvOut.file resolves to "2012-02-07-14.14.48.445000.docx"

          NewDoc resolves to "/www/smsserver/CustDocs/TESTP/2012-02-07-14.14.48.445000.docx"

          Let me know if you need anything else.

          Comment


          • #6
            I think that vvOut.contentType should not be the file extension of "DOCX" - it should be the literal "application/x-download"

            Or you could not omit vvOut.contentType on the call and add a DOCX extension to file vvFXQ100 and it will look it up for you.

            Comment


            • #7
              I had already added the record to vvFXQ100 previously. So I removed the vvOut.contentTyep from my program. Here is the latest RPG code for my download.

              Code:
                       // Send file to the browser
              
                       vvOut.download='Y';
                       vvOut.file = %Char(Name) + '.docx';
                       vvout.binary='Y';
                       vvOut_file(NewDoc:vvOut);
              After the change I still get a file name of vvcall.pgm.

              Is there anything else I should change?

              Comment


              • #8
                Now you show a lowercase '.docx'? It would need to match the case of the extension in vvFXQ100.

                Comment


                • #9
                  Sorry - case shouldn't make a difference.

                  Comment


                  • #10
                    just to confirm that the vvfxq100 is not a factor, what do you get when you specify an extension of '.doc' and not '.docx'?

                    Comment


                    • #11
                      I tried it with uppercase and it made no difference as you suggested. Do we need to get an online meeting and debug what is happening?

                      Comment


                      • #12
                        I get the same result when I change the file extension to ".doc".

                        Comment


                        • #13
                          I compared the 3.x code to 2.x code for vvOut_file and there are no differences.
                          Only a couple of things left to try - one is that the extension has to be parsed from the file name to get the content type. The routine that does that has to scan for the period. It should handle multiple periods (which you have a lot), but perhaps it could fail to come up with the proper extension. To test this, if you could change the name of the file to one that does not contain periods except for the file extension.

                          You could also specify the content type of application/x-download

                          Comment


                          • #14
                            You might need to add these directives near the top of your apache server instance configuration:

                            Code:
                            AddType application/vnd.ms-word.document.macroEnabled.12 .docm                        
                            AddType application/vnd.openxmlformats-officedocument.wordprocessingml.document docx  
                            AddType application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx  
                            AddType application/vnd.ms-powerpoint.template.macroEnabled.12 potm                   
                            AddType application/vnd.openxmlformats-officedocument.presentationml.template potx    
                            AddType application/vnd.ms-powerpoint.addin.macroEnabled.12 ppam                      
                            AddType application/vnd.ms-powerpoint.slideshow.macroEnabled.12 ppsm                  
                            AddType application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx           
                            AddType application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm               
                            AddType application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
                            AddType application/vnd.ms-excel.addin.macroEnabled.12 xlam                           
                            AddType application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb                    
                            AddType application/vnd.ms-excel.sheet.macroEnabled.12 xlsm                           
                            AddType application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx        
                            AddType application/vnd.ms-excel.template.macroEnabled.12 xltm                        
                            AddType application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx     
                            AddType application/rtf rtf
                            Compare your 2.x instance to 3.0 and you should see the difference.

                            Comment


                            • #15
                              I tried both and neither made a difference. What next?

                              Comment

                              Working...
                              X