简体   繁体   English

将二进制文件提取为 base64 字符串会导致文件不完整?

[英]Extracting binary as base64 String results in incomplete file?

I am trying to extract binary from soap response and convert it to base64 string but what happens is that I get part of the binary converted to base64 not the full binary data.我正在尝试从 soap 响应中提取二进制文件并将其转换为 base64 字符串,但实际情况是我将部分二进制文件转换为 base64 而不是完整的二进制数据。

Integration Studio: 8.1.0集成工作室:8.1.0

the soap response is as following: soap 响应如下:

--A-B--MIME-BOUNDARY--27d99311536fa8c4-18606176189--Y-Z
Content-Transfer-Encoding: binary
Content-Type: application/xop+xml; type="application/soap+xml"; charset=UTF-8
Content-ID: 
<v0-27d99311536fa8c4-18606176189@mtom.p8ce.filenet.com>
    <?xml version="1.0" encoding="UTF-8"?>
    <e:Envelope xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn35="http://www.filenet.com/ns/fnce/2005/02/ws/schema" xmlns:fn40m="http://www.filenet.com/ns/fnce/2006/11/ws/MTOM/schema" xmlns:fn40="http://www.filenet.com/ns/fnce/2006/11/ws/schema" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:e="http://schemas.xmlsoap.org/soap/envelope/">
        <e:Body>
            <GetContentResponse xmlns="http://www.filenet.com/ns/fnce/2006/11/ws/schema">
                <ContentResponse id="1" i:type="fn40:ContentElementResponse" retrievalName="test.pdf" totalSize="4586622" bufferedSize="1048576" continueFrom="offset=1048576;id={B3795692-DA06-468C-AEC9-523A3715455D};">
                    <SourceSpecification i:type="fn40:ObjectReference" classId="Document" objectId="{E408981D-FF67-4D91-B7A9-CEBEC4630AB0}" objectStore="MCIDEV"></SourceSpecification>
                    <ElementSpecification elementSequenceNumber="0"></ElementSpecification>
                    <Content i:type="fn40:InlineContent">
                        <Binary>
                            <xop:Include href="cid:v1-27d99311536fa8c4-18606176189@mtom.p8ce.filenet.com"></xop:Include>
                        </Binary>
                    </Content>
                </ContentResponse>
            </GetContentResponse>
        </e:Body>
    </e:Envelope>
--A-B--MIME-BOUNDARY--27d99311536fa8c4-18606176189--Y-Z
Content-Transfer-Encoding: binary
Content-Type: application/octet-stream
Content-Id: 
    <v1-27d99311536fa8c4-18606176189@mtom.p8ce.filenet.com>

%PDF-1.4
......
......
......
--A-B--MIME-BOUNDARY--27d99311536fa8c4-18606176189--Y-Z--

The code to extract the binary and convert it to base64 string is as follows:提取二进制并将其转换为 base64 字符串的代码如下:

<property expression="$body/fn:GetContentResponse/fn:ContentResponse/fn:Content/fn:Binary" name="DataBase64" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>

My service code is as follows:我的服务代码如下:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="StorageGetDocumentSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <propertyGroup>
        <property expression="json-eval($.username)" name="Username" scope="default" type="STRING"/>
        <property expression="json-eval($.password)" name="Password" scope="default" type="STRING"/>
        <property expression="json-eval($.objectStore)" name="ObjectStore" scope="default" type="STRING"/>
        <property name="DocumentClass" scope="default" type="STRING" value="Document"/>
        <property expression="json-eval($.documentId)" name="DocumentId" scope="default" type="STRING"/>
        <property expression="json-eval($.version)" name="Version" scope="default" type="STRING"/>
    </propertyGroup>
    <sequence key="StorageRequestValidatorSeq"/>
    <script description="Response Builder" language="js"><![CDATA[var errors = [];
    var errorProperties = mc.getPropertyKeySet();
    var it = errorProperties.iterator();      
            var i = 1;
            while(it.hasNext()){              
               var prop = it.next();
               if (prop.contains('Error')) {              
                print(prop.toString());
                errors.push(mc.getProperty(prop));     
               }    
            }
    mc.setProperty('errorList', "[" + errors.toString() + "]");]]></script>
    <filter regex="false" source="get-property('IsValid')">
        <then>
            <payloadFactory description="Response Payload" media-type="json">
                <format>
                    {"errorCode":400,"errorMessage":"One or more validation error","errorList":$1}</format>
                <args>
                    <arg evaluator="xml" expression="get-property('errorList')"/>
                </args>
            </payloadFactory>
            <property description="Set 400 response code" name="HTTP_SC" scope="axis2" type="STRING" value="400"/>
            <respond description="Response to client"/>
        </then>
        <else/>
    </filter>
    <sequence key="StorageGetMimeTypeSeq"/>
    <payloadFactory media-type="xml">
        <format>
            <soapenv:Envelope xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                <soapenv:Header>
                    <Security xmlns="http://schemas.xmlsoap.org/ws/2002/12/secext">
                        <hd:UsernameToken xmlns:hd="http://schemas.xmlsoap.org/ws/2002/12/secext">
                            <hd:Username>$1</hd:Username>
                            <hd:Password>$2</hd:Password>
                        </hd:UsernameToken>
                    </Security>
                </soapenv:Header>
                <soapenv:Body>
                    <p857:GetContentRequest validateOnly="0" xmlns:p857="http://www.filenet.com/ns/fnce/2006/11/ws/schema">
                        <p857:ContentRequest continueFrom="" cacheAllowed="1" id="1" startOffset="0">
                            <p857:SourceSpecification classId="$4" itemIndex="0" objectId="$5" objectStore="$3" 
                            serializationDuplicate="0" xsi:type="p857:ObjectSpecification"/>
                            <p857:ElementSpecification elementSequenceNumber="0" itemIndex="0"/>
                        </p857:ContentRequest>
                    </p857:GetContentRequest>
                </soapenv:Body>
            </soapenv:Envelope>
        </format>
        <args>
            <arg evaluator="xml" expression="get-property('Username')"/>
            <arg evaluator="xml" expression="get-property('Password')"/>
            <arg evaluator="xml" expression="get-property('ObjectStore')"/>
            <arg evaluator="xml" expression="get-property('DocumentClass')"/>
            <arg evaluator="xml" expression="get-property('DocumentId')"/>
        </args>
    </payloadFactory>
    <call-template target="StorageEndpointTemplate"/>
    <propertyGroup>
        <property expression="$axis2:HTTP_SC" name="HTTPStatus" scope="default" type="STRING"/>
        <property expression="$body/e:Fault/e:Reason/e:Text" name="ErrorMessage" scope="default" type="STRING" xmlns:e="http://www.w3.org/2003/05/soap-envelope"/>
        <property expression="$body/fn:GetContentResponse/fn:ContentResponse/@retrievalName" name="FileName" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
        <property expression="$body/fn:GetContentResponse/fn:ContentResponse/@totalSize" name="FileSize" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
        <property expression="$body/fn:GetContentResponse/fn:ContentResponse/fn:Content/fn:Binary" name="DataBase64" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>
    </propertyGroup>
    <log level="headers"/>
    <log level="custom">
        <property expression="get-property('FileName')" name="FileNameLog"/>
        <property expression="get-property('FileSize')" name="FileSizeLog"/>
    </log>
    <filter regex="true" source="boolean(get-property('ErrorMessage'))=''">
        <then>
            <payloadFactory media-type="json">
                <format>
                {
                 "fileName":"$1",
                 "fileSize": $2,
                 "mimeType":"$3",
                 "dataBase64":"$4"
                }
                </format>
                <args>
                    <arg evaluator="xml" expression="get-property('FileName')"/>
                    <arg evaluator="xml" expression="get-property('FileSize')"/>
                    <arg evaluator="xml" expression="get-property('MimeType')"/>
                    <arg evaluator="xml" expression="get-property('DataBase64')"/>
                </args>
            </payloadFactory>
        </then>
        <else>
            <property name="HTTP_SC" scope="axis2" type="STRING" value="400"/>
            <payloadFactory description="Response Payload" media-type="json">
                <format>{"errorCode": "$1","errorMessage": "$2"}</format>
                <args>
                    <arg value="400"/>
                    <arg evaluator="xml" expression="get-property('ErrorMessage')"/>
                </args>
            </payloadFactory>
        </else>
    </filter>
</sequence>

EDIT : I also tried the base64Encode as follows:编辑:我也尝试了base64Encode如下:

<property expression="base64Encode($body/fn:GetContentResponse/fn:ContentResponse/fn:Content/fn:Binary)" name="DataBase64" scope="default" type="STRING" xmlns:fn="http://www.filenet.com/ns/fnce/2006/11/ws/schema"/>

And it also results in corrupted base64String它还会导致 base64String 损坏

I found out that the issue was not related to WSO2 at all but a fil.net limitation我发现这个问题根本与 WSO2 无关,而是一个fil.net 限制

Inline Content Retrieval Limit default is 1 MB so that fil.net API itself was returning 1 MB only of the file.内联内容检索限制默认为 1 MB ,因此 fil.net API 本身仅返回 1 MB 的文件。

https://www.ibm.com/docs/en/fil.net-p8-platform/5.5.x?topic=engine-improving-content-uploads-downloads https://www.ibm.com/docs/en/fil.net-p8-platform/5.5.x?topic=engine-improving-content-uploads-downloads

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将图像作为 base64 字符串发送到 Firebase Cloud Functions 的效率 - Efficiency sending images as base64 string to Firebase Cloud Functions 如何从 Azure Function 返回 base64 图像作为二进制数据 - How to return base64 image from Azure Function as binary data 如何使用 AWS Lambda [NodeJS] 将 base64 编码字符串作为图像上传到 S3 - How to upload a base64 encoding string as an image to S3 using AWS Lambda [NodeJS] 从 base64 编码字符串解析 Azure 逻辑应用程序中的 JSON 数组,以在 For_each 中使用 - Parsing JSON array in Azure Logic App from base64 encoded string to use in For_each 如何通过AWS api-gateway返回一个Base64编码的zip文件供下载 - How do I return a Base64 encoded zip file through AWS api-gateway for download 通过 ApiGateway 下载二进制文件 (nosql db) 由于配置错误导致执行失败:无法对正文进行 base64 解码 - Download binary (nosql db) through ApiGateway gives Execution failed due to configuration error: Unable to base64 decode the body 如何返回不在 base64 中的图像 - How to return image NOT in base64 base64 编码 io.Reader - base64 encode io.Reader 将 base64 字符串编码图像/字节图像作为图像传递到 Firebase ML Vision Flutter 中进行处理 - Passing a base64 string encoded image/ byte image as an image for processsing in Firebase ML Vision in Flutter 如何使用 AWS SES 在 email 中将 base64 字符串显示为图像 - How to display base64 string as image in email, using AWS SES
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM