简体   繁体   English

SAPUI5 FileUploader:无法找到文件并将其追加到FormData()

[英]SAPUI5 FileUploader: Cannot find and append file to FormData()

How do I access the file that I select with my fileuploader? 如何访问通过fileuploader选择的文件?

Any solutions are welcome. 欢迎任何解决方案。

var oInput = new sap.m.Input();  
var oFileUploader = new sap.ui.unified.FileUploader();

var oButton = new sap.m.Button({
text: "Send data",
press: function(){

    var oFormData = new FormData();

    oFormData.append("myTitle", oInput.getValue());
    oFormData.append("myFile", ****This is where I want to insert my file****);

    var xhr = new XMLHttpRequest;
      xhr.open('POST', 'www.myUrl.com/foo/bar', true);
      xhr.send(oFormData);

}
});

Found the answer myself: 自己找到答案:

oFileUploader.setUploadOnChange(true);

    var oFormData = new FormData();

    oFormData.append("title", "I am the title");

    jQuery.sap.domById(oFileUploader.getId() + "-fu").setAttribute("type", "file");
    oFormData.append("document", jQuery.sap.domById(oFileUploader.getId() + "-fu").files[0]);

    jQuery.ajax( {
      url: "www.myWebsite.com/path",
      data: oFormData,
      cache: false,
      contentType: false,
      processData: false,
      type: 'POST',
      success: function(data) {

      },
      error: function() {

      }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM