Zusee Weekin
Zusee Weekin

Reputation: 1358

Error in adding image to Salesforce static resource using Mule4

I have to add images to Salesforce static resources via mule integration. I'm using Salesforce create connector. I'm getting those images from the HTTP listener as multipart/form-data. I get the image out from it and tried to update it in the salesforce static resource as application/octet-stream.

 output application/octet-stream
    ---
    payload.parts.image.content

But I'm getting an error message as (error.description)

""Cannot coerce Binary { encoding: UTF-8, mediaType: application/octet-stream; charset=UTF-8, mimeType: application/octet-stream, raw: org.mule.weave.v2.el.SeekableCursorStream@54ca576e, contentLength: 6039 } ("/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBYVFRgVFRYYGBgaGRgcGhwZGRgcGRocGhgaGhoh...) to Array" evaluating expression: "payload"." 

Console log

Message               : "Cannot coerce Binary { encoding: UTF-8, mediaType: application/octet-stream; charset=UTF-8, mimeType: application/octet-stream, raw: org.mule.weave.v2.el.SeekableCursorStream@54ca576e, contentLength: 6039 } ("/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAoHCBYVFRgVFRYYGBgaGRgcGhwZGRgcGRocGhgaGhoh...) to Array" evaluating expression: "payload".
Element               : googledriveimageuploaderFlow/processors/4 @ googledriveimageuploader:googledriveimageuploader.xml:49 (Create)
Element DSL           : <salesforce:create type="StaticResource" doc:name="Create" doc:id="e2c59345-e6b8-4e85-85a9-5ec698ba6676" config-ref="Salesforce_Config"></salesforce:create>
Error type            : MULE:EXPRESSION
FlowStack             : at googledriveimageuploaderFlow(googledriveimageuploaderFlow/processors/4 @ googledriveimageuploader:googledriveimageuploader.xml:49 (Create))

salesforce create connector xml

<salesforce:create type="StaticResource" doc:name="Create" doc:id="e2c5927e-e6b8-4e34-85a9-567c698ba6676" config-ref="Salesforce_Config">
        </salesforce:create>

Saleforce connector vertion is 10.12.4

Above away is working for saving the image in local drive and google drive but not for salesforce static resource. Can some one point me how do imege update in salesforce static resource?

Upvotes: 0

Views: 380

Answers (1)

aled
aled

Reputation: 25699

Usually Salesforce APIs expect binary files to be encoded with base64. You can use DataWeave base64() function. In this particular case you need to respect the format expected by the Salesforce API. You need to send an array and each element has to have the expected metadata information.

Example:

%dw 2.0
import * from dw::core::Binaries
output application/java
---
[{
    Title: "MyImage",
    PathOnClient : "myimage.jpg",
    VersionData: toBase64(payload.parts.image.content)
}]

Source: https://help.mulesoft.com/s/article/How-to-create-a-file-in-salesforce-using-salesforce-connector

Upvotes: 0

Related Questions