使用UI5上传SAP HANA XS文件

时间:2013-05-03 07:51:46

标签: sap hana hana-xs sapui5

我正在尝试在HANA XS服务器上的UI5应用程序中实现文件上载。 我找不到很多信息怎么做 - 有人有个主意吗?

2 个答案:

答案 0 :(得分:6)

这是纯文本文件上传的简单实现:

客户端js:

doUpload: function() {
    var uploadField = document.getElementById("ulUploader1-fu");
    var file = uploadField.files[0];

    var reader = new FileReader();
    reader.onload = function (event) {
    var source = event.target.result; // this is the binary values
    var name = file.name;      

    $.ajax({
        url: "/services/upload.xsjs?cmd=Import",
        type: "PUT",
        processData: false,
        contentType: file.type,
        data: source,
        xhr: function() {
            var req = $.ajaxSettings.xhr();
            if (req) {
                if (req.overrideMimeType) {
                    req.overrideMimeType('text/plain; charset=x-user-defined');
                }
                if (req.sendAsBinary) {
                    req.send = req.sendAsBinary;
                }
            }
            return req;
        },
        error: function(xhr, textStatus, errorThrown){
            alert(xhr.responseText);
        },
        success: function() {
            reader.onload = null;
        }
        });
    };
    reader.readAsText(file);
}

这是服务器端xsjs服务:

    function doImport() {
    var data = '', conn = $.db.getConnection(), pstmt;  

    if($.request.body){
        data = $.request.body.asString();     
    }

    var conn = $.db.getConnection();
    var pstmt = conn.prepareStatement( 'INSERT INTO "TEST"."UPLOAD" (ID, MIMETYPE, DATA) VALUES(?,?,?)' );

    pstmt.setInteger(1,1);
    pstmt.setString(2,"text/plain");
    pstmt.setString(3,data);

    pstmt.execute();
    pstmt.close();

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

    doResponse(200,'');

    $.response.contentType = 'text/plain';
    $.response.setBody('Upload ok');
    $.response.status = 200;
}

答案 1 :(得分:0)

XS没有“即时消费”服务可以让您这样做。您当然可以在HANA数据库中创建表,创建列类型BLOB,然后在XS上构建服务,允许您从前端上载文件。我希望有所帮助。