forcedotcom / forcedotcom/wsc

Inconsistency in Read and Write of Body of an Attachment

Open
#166 0 comments 0 reactions 0 assignees View on GitHub
Work Created
Dominant language
Java
Stars
276
Forks
223
PR merge metrics
No merged PRs in 30d

Description

I am trying to create an Attachment as follows:
SObject creatable= new SObject();
creatable.setType(objectType);
creatable.setField("Name", "sfdcTest1.pdf");
creatable.setField("ParentId", "a0I2300000BbZ1S");

InputStream in = new FileInputStream("C:\dev\java\workspace\sforce-soap-jar\src\sfdcTest1.pdf");
String body = base64Encode(in);// Step-A. this method base64 encodes the content of the input stream
byte[] bodyBytes = body.getBytes(Charsets.UTF_8);
in.close();
creatable.setField("Body", bodyBytes);
connection.create(new SObject[]{creatable});

This returns a successful response but when I try to open this attachment in Chrome browser after logging into my salesforce organization, it says "'Failed to load PDF document".
On investigating further, I found that if I do not base64 encode at Step-A, then everything works fine. Looks like the jar performs the base64 encoding by itself.
But then, if I try to retrieve the same Attachment's body back, then I am having to do base64 decoding on my own. So, both operations, read and write are not consistent. The jar should either do both encoding as well as decoding on it's own or not do anything at all. However, right now, it's encoding while creating but not decoding while retrieving.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.