Skip to Content
0

Upload image to SAP from SAPUI5 using oData

Feb 27, 2017 at 05:49 PM

245

avatar image
Former Member

Hi to all,

i have created a small SAPUI5-Application where I can retrieve images from the Backend via oData-Service and show it in an sap.m.Image-Object.

My App is also able to get an image from the camera using the native plug-ins and show it in my Object.

Now my requirement is to send the captured image to SAP with an oData-Service. Can anyone provide me a small piece of code what I have to doe on the frontend? The backend is clear to me.

What I tried is the following:

jQuery.ajax({
                url : "/sap/opu/odata/sap/ZLAGER_USER_SRV/MaterialBilderSet",
                type : "POST",
                headers: {
                    slug: this.getView().byId("idMat").getValue(),
                    "x-csrf-token": "abcde"
                },
                data : {
                    data : this.getView().byId("matImage").getSrc()
                },
                success : function(data, textStatus) {
                    MessageToast.show(data.DATA.MESSAGE);
                },
                error : function(data, textStatus) {
                    MessageBox.error(data.statusText, {
                        actions : [ MessageBox.Action.CLOSE ],
                    });

But without succes. I get an Error with "Forbidden" whenever i try to upload the Image.

Thanks a lot,

Mathias

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Mar 01, 2017 at 01:47 PM
0

Thanks Veera,

found it on my own.

I have created a similar solution as it is described in https://blogs.sap.com/2015/04/27/file-upload-using-sapui5-control/

Step 2. Seems to work.

Share
10 |10000 characters needed characters left characters exceeded
Veeraraghavan Narasimhan
Feb 27, 2017 at 11:11 PM
0

Hello Mathias,

The token needs to be correctly passed. Was this fetched in the previous call? If you fetch the correct token provided by the oData service then it should work.

Thanks and Regards,

Veera

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Feb 28, 2017 at 06:25 AM
0

Hi Veera,

thanks for your quick answer but I am a little bit confused. What is the token? And how can i fetch it?

For the capture of a photo i use this code:

            var oPlug = navigator.camera;
            var oImage = this.getView().byId("matImage");
            var that = this;
            oPlug.getPicture(function(imageData) {
                oImage.setSrc("data:image/jpeg;base64," + imageData);
                that.getView().byId("idSave").setEnabled(true);
            }, function(error) {
                MessageBox.error("Fehler: " + error);
            }, {
                quality : 50,
                destinationType : oPlug.DestinationType.DATA_URL,
                allowEdit : true,
                targetHeight : 200,
                targetWidth : 200,
                correctOrientation : true
            });

I´m not sure how I can fetch any token here.

Thanks,

Mathias

Show 1 Share
10 |10000 characters needed characters left characters exceeded
0