使用SAPUI5 UploadCollection请求Payload问题

时间:2017-07-19 13:01:05

标签: parameters request sapui5 payload

我正在使用SAPUI5 UploadCollection来实现多种即时上传功能。

我正在使用像这样的参数

            <parameters>
                <UploadCollectionParameter name="Nbr" value="12" />
            </parameters>
            <headerParameters>
                <UploadCollectionParameter name="Nbr" value="12" />
            </headerParameters>

但是当我查看Chrome浏览器网络标签的开发者工具时,我没有收到请求有效负载。

我正在使用以下代码。

<UploadCollection
                id="UploadCollection"
                maximumFilenameLength="55"
                maximumFileSize="10"
                multiple="false"
                showSeparators="All"
                change="onChange"
                fileSizeExceed="onFileSizeExceed"
                selectionChange="onSelectionChange"
                typeMissmatch="onTypeMissmatch"
                uploadComplete="onUploadComplete"
                beforeUploadStarts="onBeforeUploadStarts"
                uploadTerminated="onUploadTerminated"
                items="{MeterTicketsModel>/returnData}"

                mode="MultiSelect">

                <toolbar>
                    <OverflowToolbar id="myId" >
                        <Title id="attachmentTitle"/>
                        <ToolbarSpacer/>
                        <Button id="downloadButton" text="Download" press="onDownloadItem" enabled="false" type="Transparent"></Button>
                        <Button id="versionButton" text="Upload a new version" press="onVersion" enabled="false" type="Transparent"></Button>
                        <UploadCollectionToolbarPlaceholder></UploadCollectionToolbarPlaceholder>
                    </OverflowToolbar>
                </toolbar>
                <items>
                    <UploadCollectionItem
                        documentId="{documentId}"
                        fileName="{MeterTicketsModel>fileName}"
                        mimeType="{mimeType}"
                        thumbnailUrl="{thumbnailUrl}"
                        url="{url}"
                        enableEdit="false"
                        enableDelete="false"
                        visibleDelete="false"
                        visibleEdit="false"
                        attributes="{path : 'attributes', templateShareable : 'true'}"
                        statuses="{path : 'statuses', templateShareable : 'true'}"
                        selected="{selected}">
                        <attributes>
                            <ObjectAttribute
                                title="{title}"
                                text="{parts : ['text', 'type'], formatter : '.formatAttribute'}"
                                active="{active}"/>
                        </attributes>
                        <statuses>
                            <ObjectStatus
                                title="{title}"
                                text="{text}"
                                state="{state}"
                                icon="{icon}"
                                iconDensityAware="{iconDensityAware}"
                                textDirection="{textDirection}"/>
                        </statuses>
                    </UploadCollectionItem>
                </items>
                <parameters>
                    <UploadCollectionParameter name="Nbr" value="12" />
                </parameters>
                <headerParameters>
                    <UploadCollectionParameter name="Nbr" value="12" />
                </headerParameters>
            </UploadCollection>

即使我在控制器中添加了params,我也没有在控制台中获得Request Payload。 我在beforeUploadStarts事件中使用的以下代码。

onBeforeUploadStarts: function(oEvent) {
    var oFileUploader = this.byId("UploadCollection");
            var sUrl = "some url";
            oFileUploader.setUploadUrl(sUrl);
            var NbrParam = new sap.m.UploadCollectionParameter({
            name : "xyz",
            value : 5
            });

   oEvent.getParameters().addHeaderParameter(NbrParam );
   oFileUploader.addParameter(NbrParam );
 });

1 个答案:

答案 0 :(得分:1)

在控制器中添加

onFileUploadChange: function (oEvent) {
                var oUploadCollection = oEvent.getSource();
                // Header Token
                var oCustomerHeaderToken = new UploadCollectionParameter({
                    name: "x-csrf-token",
                    value: "securityTokenFromModel"
                });
                oUploadCollection.addHeaderParameter(oCustomerHeaderToken);
            },

onBeforeUploadStarts: function (oEvent) {
                var oCustomerHeader = new sap.m.UploadCollectionParameter({
                    name: "slug",
                    value: oEvent.getParameter("fileName")
                });
                oEvent.getParameters().addHeaderParameter(oCustomerHeader);
            },

我遇到了同样的问题,但上述更正对我有用。您仍然不会在控制台中看到请求有效负载,但我的后端ABAP类正在接收文件内容。