cancel
Showing results for 
Search instead for 
Did you mean: 

FileLoader - unable to see uploaded file

former_member187673
Active Participant
0 Kudos


Hi, I've created an XS project to use the sap.ui.commons.FileLoader API to upload a file to the XS server. I've included the sap.ui.demokit.FileUploadIntrospector so that I can check if the file has uploaded successfully. Everything looks good but when I test I'm unable to see the file in the Introspector window after I do the upload. The uploadComplete event fires successfully. I verified this by adding in an alert.

FileLoader

  createContent : function(oController)

      {

            jQuery.sap.require("jquery.sap.resources");

        

              var oPanel = new sap.ui.commons.Panel().setText("File Uploader Test 4");

        

              var oFileUploader = new sap.ui.commons.FileUploader("MyFileLoader");             

              oFileUploader.setUploadUrl("../upload_dir");         

              oFileUploader.setUploadOnChange(true); 

              oFileUploader.attachUploadComplete(oController.doFileLoadComplete);       

              oPanel.addContent(oFileUploader);

  

              var oButton = new sap.ui.commons.Button({

                    id : this.createId("MyButton"), 

                    text : "Upload"

            });

        

              oButton.attachPress(function(){oFileUploader.upload();});         

              oPanel.addContent(oButton);

            return oPanel;

      }

      

FileUploadIntrospector

<script>

                    var oFileList = new sap.ui.demokit.FileUploadIntrospector({

                          uploadUrl : "../upload_dir-check",

                          autoRefreshInterval : 2000, /* ms */

                          height: '12em',

                          width: '95%'

                    });

                    oFileList.placeAt("upload-check");

              </script>

                  

                                              

      </head>

      <body class="sapUiBody" role="application">

              <div id="content"></div>

          

              <h3>Upload Check</h3>

                          <p>To verify the results of the upload, check the following file list. It displays all

                          files in the upload area (server side) of this application and is updated automatically.</p>

                          <br><br>

                          <div id="upload-check"></div>

          

                  

          

      </body>

After upload I should see the file appear in the introspector window below

Any ideas why the file does not show up? Is there any other way to check if the upload worked?

To note: I created the folder "upload_dir" in my project as the destination folder for the upload. Is there anything special that I need to set up for this?

Any advice would be appreciated.

Thanks

Peter

Accepted Solutions (0)

Answers (1)

Answers (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I believe you have misunderstood how the upload works.  You can't just give it a folder in the repository as the target URL.  The uploader is trying to a post to that URL, but that alone won't write the file into the HANA repository.  You really need custom XSJS code and point the file upload URL to the XSJS service.  This XSJS code would be responsible for storing the content.  Generally you would store the content into a database table, however.  The APIs to write files into the HANA Content Repository are not released for customer or partner usage yet.

former_member187673
Active Participant
0 Kudos

Ok, thanks Thomas, I understand what you are saying. And actually I do want to store the contents of the file in a database table. I was hoping that I may be able to integrate this with the data provisioning table-import functionality. I have a seperate discussion raised about this - http://www.saphana.com/thread/2554.

Is that possible? Or as you say would need to wait for the APIs to become available?

Former Member
0 Kudos

Hello Thomas,

is there an example how the serverside code in the xsjs service could should look?

I need to implement data upload too but can't find an example out there..

Thanks!

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I couldn't speak to the data provisioning, however if you want to write the content into a database table; you can do that already using custom XSJS.

former_member187673
Active Participant
0 Kudos

Hi Ben, here is some sample server side code I put together which reads from uploaded file and uses batch insert. Assumes 1 column table...

var conn = $.db.getConnection();
var pstmt = conn.prepareStatement( "insert into my_schema.my_table values(?)" );

var file_body = $.request.entities[0].body.asString();
var allTextLines = file_body.split(/\r\n|\n/);

var lines;
var entries;
var cells;

pstmt.setBatchSize(allTextLines.length);

for (lines=0; lines<allTextLines.length; lines++)
{
       entries = allTextLines[lines].split(',');
       cells = entries.splice(0,allTextLines.length);
      
       pstmt.setString(1,cells[0]);
       pstmt.addBatch();
}
pstmt.executeBatch();
pstmt.close();


conn.commit();
conn.close();

Former Member
0 Kudos

Hi Peter, thanks a lot!

I've tried it, but for some reason $.request.entities[0].body.asString(); is always completely empty.