cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with UploadSetwithTable - Unsupported Media Type (415) in RAP (S/4HANA Public Cloud)

Cebin
Newcomer
0 Kudos
183

Hello SAP Experts,

I am working on a RAP-based application in S/4HANA Public Cloud where I need to attach multiple files and upload them using the UploadSetwithTable control.

However, I am encountering the following error during upload:

Error Response:

{
"message": "The server is refusing to process the request because the entity has an unsupported format"
}

HTTP Status: 415 (Unsupported Media Type)

Implementation Details:-

My Fragment code: 

<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core"
    xmlns:f="sap.f" xmlns:upload="sap.m.upload">
   
    <Dialog id="uploadDialog" title="Upload File" draggable="true" resizable="true" contentWidth="50%" contentHeight="50%">
        <content>
            <Table id="table-uploadSet"
                inset="true"
                autoPopinMode="true"
                hiddenInPopin="None"
                items="{path: 'attachmentModel>/Attachment', templateShareable: false}">
                <headerToolbar>
                    <OverflowToolbar>
                        <Title text="Documents" level="H2" />
                        <ToolbarSpacer />
                        <ToolbarSeparator />
                        <upload:ActionsPlaceholder id="uploadButton" placeholderFor="UploadButtonPlaceholder" />
                    </OverflowToolbar>
                </headerToolbar>

                <dependents>
                    <plugins.UploadSetwithTable
                        id="uploadSet"
                        uploadUrl="/path"
                        multiple="true"
                        beforeUploadStarts=".onBeforeUploadStarts"
                        uploadCompleted=".onUploadCompleted"
                        cloudFilePickerEnabled="true"
                        actions="uploadButton">
                        <rowConfiguration>
                            <upload.UploadItemConfiguration
                                fileNamePath="Filename"
                                mediaTypePath="Mimetype"
                                urlPath="url"
                                previewablePath="previewable"
                                fileSizePath="fileSize"
                                isTrustedSourcePath="trustedSource"/>
                        </rowConfiguration>
                    </plugins.UploadSetwithTable>
                </dependents>

                <columns>
                    <Column id="fileName" importance="High">
                        <header>
                            <Label text="File Name" />
                        </header>
                    </Column>
                    <Column id="actionButton" importance="High" />
                </columns>  

                <items>
                    <ColumnListItem>
                        <cells>
                            <Text text="{attachmentModel>Filename}" />
                            <Button type="Transparent" icon="sap-icon://decline" press="onRemoveHandler"/>
                        </cells>
                    </ColumnListItem>
                </items>
            </Table>
        </content>
        <endButton>
            <Button text="Close" type="Transparent" press="onCloseFileUploadDialog"/>
        </endButton>
    </Dialog>
</core:FragmentDefinition>

Controller code: 

onBeforeUploadStarts: function (oEvent) {
            var oUploadSet = oEvent.getSource();           
            var oItem = oEvent.getParameter("item"); // Get the item inside mParameters

            var oModel = this.getView().getModel("zmm_sd_pr_atch");
            var csrfToken = oModel.getHttpHeaders()["X-CSRF-Token"];
 
            var sContentType = oItem.getMediaType() || "application/octet-stream";
            oItem.addHeaderField(
                new sap.ui.core.Item({ key: "x-csrf-token", text: csrfToken })
            );
            oItem.addHeaderField(
                new sap.ui.core.Item({ key: "slug", text: oItem.getFileName() })
            );
            oItem.addHeaderField(
                new sap.ui.core.Item({ key: "Content-Type", text: sContentType  })
            );
},
onUploadCompleted: function (oEvent) {
            var iResponseStatus = oEvent.getParameter("status");
       
            if (iResponseStatus === 201) {  // Check if upload is successful
                this.getView().getModel("zmm_sd_pr_atch").refresh(true);
                MessageToast.show("Document Added Successfully");
            } else {
                MessageToast.show("File upload failed.");
            }
        },
 

Any guidance on proper request formatting would be greatly appreciated!

Thanks in advance! 

 
 
 

Accepted Solutions (0)

Answers (0)