on 05-02-2013 10:13 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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();
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.