cancel
Showing results for 
Search instead for 
Did you mean: 

CAP/SAPUI5 FileUploader fires GET instead of PUT

cinemandre
Advisor
Advisor

I tried using the fileUploader in UI5 to upload a single audiofile to AWS S3.

This is my schema.cds:

entity Item : cuid, managed {
    title    : String(100);
    Category : Association to one Categories;
    tags     : String;
    @Core.MediaType : 'audio/wav'
    content  : LargeBinary;
}

And in the XML-View I implemented a simple FileUploader:

<unified:FileUploader
                    id="fileUploader"
                    useMultipart="false">
                </unified:FileUploader>
                <Button 
                    id="uploadBtn"
                    text="Upload File"
                    press="handleUploadPress"/>

To upload the file to S3 I first need a POST Request on the Item-Entity and then use the created Item_ID to upload the file. To do this, I thought of this function:

handleUploadPress : async function() {
            var oModel = new sap.ui.model.json.JSONModel();
            var oUploader = this.byId('fileUploader');
            jQuery.ajax({
                type: 'POST',
                contentType: 'application/json',
                url: 'http://localhost:4004/items/Item',
                dataType: 'json',
                data: '{}',
                asnyc: false,
                success: function(data){
                    oModel.setData(data);
                    console.log(oModel.oData.ID);
                    oUploader.setUploadUrl(`http://localhost:4004/items/Item(${oModel.oData.ID})/content`);
                    oUploader.setHttpRequestMethod('PUT');
                    oUploader.upload();
                }
            });

When I follow the same steps in Postman, the upload works just fine.

But using the FileUploader with HttpRequestMethod set on Put I get the following error:

[cds] - GET /items/Item(056be3f7-dd32-4bcf-b03a-4cc1b24025e4)/content?container-audioapp---worklist--fileUploader=3.wav&_charset_=UTF-8&container-audioapp---worklist--fileUploader-data=
[cds] - NoSuchKey: The specified key does not exist.

I dont get it why a GET Request is fired..

This is the GET Request that is fired

Accepted Solutions (0)

Answers (0)