cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Upload error

TimMuchena
Participant
0 Kudos
2,499

Hi all

I am getting the following error when I upload a file

POST http://localhost:62541/sap/opu/odata/SAP/ZTEST_SRV_01/attachSet('value') 405 (Method Not Allowed)

I am using the following code to do the actual upload

Regards

View Entire Topic
ugurkaya
Active Participant

Hi Timothy,

Here is my working code for file uploader, have a look.

Regards

Ugur


onAttach : function(oEvent){

  var sGuid = this._sGuid;

  var oUploadDialog = new sap.ui.commons.Dialog();

        oUploadDialog.setTitle("Upload photo");

        var oModel = this.getView().getModel();

        oModel.refreshSecurityToken();

        var oHeaders = oModel.oHeaders;

        var sToken = oHeaders['x-csrf-token'];

        var oHeaderParameter = new sap.ui.unified.FileUploaderParameter({

        name: "x-csrf-token",

        value: sToken

        });

       

        // prepare the FileUploader control

       

        var oFileUploader = new sap.ui.unified.FileUploader({

            uploadUrl : "/sap/opu/odata/sap/ZUI5_XXXX_SRV/OrderSet(guid'"+sGuid+"')/FileUploadSet",

            name: "simpleUploader",

            tooltip: "Yüklenecek dosyayı seçin",

            maximumFileSize: 3.000,

            buttonText: "Dosya Seç",

            additionalData: "Yükle",

            fileType: ["jpg", "png", "bmp"],

            icon: "sap-icon://attachment",

            title:"Dosya",

            uploadOnChange: false,

            sendXHR: true,

            useMultipart: false,

            placeholder: "...",

            style: "Emphasized",

            headerParameters: [ oHeaderParameter ],

            uploadProgress : function (oEvent){

            sap.ui.getCore().byId("__xmlview2").setBusy(true);

            this.setBusy(true);

            console.log("uploadProgress");

            },

            fileSizeExceed : function (oEvent) {

            sap.m.MessageToast.show("Dosya boyutu en fazla 3 megabyte olabilir!");

            },

            saveClicked: function (oEvent){

            console.log("save clicked",oEvent);

            },

            BeforeUploadFile: function (oEvent){

            console.log("before upload",oEvent);

            },

            uploadComplete: function (oEvent) {

            console.log("Event",oEvent);

                var sResponse = oEvent.getParameter("response");

                console.log(sResponse);

                if (sResponse) {

                    oUploadDialog.close();

                    oModel.refresh();

//                    console.log("uploadComplete");           

                   

                    if (oEvent.mParameters.status == '400'){

                    console.log(oEvent.mParameters);

                    var sMessage = oEvent.mParameters.response;

                    sap.m.MessageBox.show( 

                    sMessage, 

               sap.m.MessageBox.Icon.ERROR, 

               "Hata!" 

        );

                    }else{

                    console.log(oEvent.mParameters);

                    sap.m.MessageToast.show("Yükleme tamamlandı");

                    };

                   

                    sap.ui.getCore().byId("__xmlview2").setBusy(false);

                    this.setBusy(false);

                       

                }

            }                   

        });

       

        // create a button to trigger the upload

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

            text:'Yükle',

            press:function() {

                // call the upload method

            console.log("oFileUploader",oFileUploader);

            var sFileName = oFileUploader.oFileUpload.files[0].name;

            console.log("sFileName",sFileName);

                oFileUploader.insertHeaderParameter(

                new sap.ui.unified.FileUploaderParameter({

                name: "slug",

                value: encodeURIComponent(sFileName) ,

                })

                );

                oFileUploader.upload();

            }

        });

       

        oUploadDialog.addContent(oFileUploader);

        oUploadDialog.addContent();

        oUploadDialog.addContent(oTriggerButton);

        oUploadDialog.open();

  },