如何上传SAPUI5中的文件

时间:2013-07-01 07:11:31

标签: sap sapui5

如何使用SAPUI5在SAP Netweaver服务器上传文件?我试图使用FileUploader上传文件,但如果任何人都可以帮助它将不会得到运气将非常感激。在此先感谢

3 个答案:

答案 0 :(得分:1)

在研究了这个问题之后我终于解决了这个问题我自己放了一个文件控制器和一个 uploader in php ,它返回了与文件相关的详细信息,我们可以用它来上传它在服务器上。

这是我用过的代码。

  

fileUpload.html

<!DOCTYPE html>  
<html><head>  
    <meta http-equiv='X-UA-Compatible' content='IE=edge' />  
    <title>Hello World</title>  

    <script id='sap-ui-bootstrap' src='http://localhost/resources/sap-ui-core.js' data-sap-ui-theme='sap_goldreflection'  
    data-sap-ui-libs='sap.ui.commons'></script>   

<script>  
    var layout = new sap.ui.commons.layout.MatrixLayout();
    layout.setLayoutFixed(false);
    // create the uploader and disable the automatic upload
    var oFileUploader2 = new sap.ui.commons.FileUploader("myupload",{
                         name: "upload2",
                         uploadOnChange: true,
                         uploadUrl: "uploader.php",
                         uploadComplete: function (oEvent) {
    var sResponse = oEvent.getParameter("response");
    if (sResponse) {
        alert(sResponse);
    }
    }});                        
    layout.createRow(oFileUploader2);
    // create a second button to trigger the upload
    var oTriggerButton = new sap.ui.commons.Button({
                         text:'Trigger Upload',
                         press:function() {
    // call the upload method
    oFileUploader2.upload();

    $("#myupload-fu_form").submit();
    alert("hi");
    }
    });
    layout.createRow(oTriggerButton);
    layout.placeAt("sample2");                
</script>

</head>
<body class='sapUiBody'>
    <div id="sample2"></div>  
</body>
</html>
  

uploader.php

<?php
    print_r($_FILES);
?>

答案 1 :(得分:1)

清单,组件和索引文件都没有添加任何内容。它对我有用,你只需要将列数改为你想要的文件。

UploadFile.view.xml

<meta-data  android:name="VERSION"  android:value="2" />

UploadFile.controller.js

<VBox>
    <sap.ui.unified:FileUploader id="idfileUploader" typeMissmatch="handleTypeMissmatch" change="handleValueChange" maximumFileSize="10" fileSizeExceed="handleFileSize" maximumFilenameLength="50" filenameLengthExceed="handleFileNameLength" multiple="false" width="50%" sameFilenameAllowed="false" buttonText="Browse" fileType="CSV" style="Emphasized" placeholder="Choose a CSV file"/>
    <Button text="Upload your file" press="onUpload" type="Emphasized"/>
</VBox>

答案 2 :(得分:0)

如果我们能看到你的代码就好了。

这应该有效。

var layout = new sap.ui.commons.layout.MatrixLayout();
layout.setLayoutFixed(false);

// create the uploader and disable the automatic upload
var oFileUploader2 = new sap.ui.commons.FileUploader({
    name : "upload2",
    uploadOnChange : false,
    uploadUrl : "../../../upload"
});
layout.createRow(oFileUploader2);

// create a second button to trigger the upload
var oTriggerButton = new sap.ui.commons.Button({
    text : 'Trigger Upload',
    press : function() {
        // call the upload method
        oFileUploader2.upload();
    }
});
layout.createRow(oTriggerButton);

layout.placeAt("sample2");