16
votes
Accepted
How to combine multiple Blob in apex to get single Blob value
It is possible to do it by converting Blob to Hex using EncodingUtil.convertToHex() method, concat the Hex Sequence and then convert concatenated Hex string back to Blob using EncodingUtil....
13
votes
Accepted
Why is String.valueOf(Blob) different that Blob.toString()?
String.valueOf returns Blob[X] for Blob values. I believe it does it this way because System.debug internally uses String.valueOf, and debugging a potentially non-Unicode stream into a Unicode String ...
12
votes
Accepted
MD5 Blob Cannot Convert to String
Instead of toString, you need to actually use EncodingUtil.convertToHex to get the output you expect:
String myString = 'Some String';
system.debug(myString);
Blob myBlob = Blob.valueOf(myString);
...
10
votes
Accepted
How to generate a >5 MB blob for an Apex test class
You can use the string repeat method to build a long string, and then pass that to a Blob.
Blob data = Blob.valueOf('a'.repeat(5242880));
7
votes
Accepted
Returning a blob to a lightning component split error
You must use base-64 encoding if you want to do it this way. The reason why is that internally, Lightning uses JSON, so passing binary data through either way may have unexpected results. If necessary,...
6
votes
How to use Blob inside a Trigger (BLOB is not a valid UTF-8 string)?
You have somehow embed the binary data into the field. Here's one way:
trigger Update_image on FeedItem (after insert) {
id Travelid ;
blob img; // Just binary data, thanks!
List<...
6
votes
Accepted
Body not a variable of ContentVersion?
For ContentVersion, the property that contains the blob data is 'VersionData'. Line 6 should be changed to:
controller.file.VersionData = Blob.valueOf('populated');
See more here:
https://...
5
votes
Send Blob file via Apex Rest Callout
You can't use both setBody and setBodyAsBlob in the same request. Also, if you're using multipart/form-data, you have to build a multipart payload. That means that you'll need to do something like the ...
5
votes
Accepted
Save base64 data as Attachment
Did you set the contentType as application/pdf? I tried this following code and it is working for me.
String jsonStr = '<Base64 String>';
Attachment attach = new Attachment();
attach....
5
votes
Accepted
What Field Type should be used to assign Blob primitive data type?
Alas, Salesforce doesn't support custom fields of the Blob type. Internally SF use Blob fields though (e.g. attachments, content files). Anyways, you have several options here. (1) Save your Blob as ...
5
votes
Unsupported mime Type when creating Blob instance into lightning community
We had the same problem and we opened a case: we've been told that the LockerService whitelisted the following MIME Types:
application/octet-stream
application/json
video/
audio/
image/
font/
text/...
5
votes
Accepted
How to check Blob objects for equality?
The equals operator == does work as expected with Blob, so there's no reason to jump through extra hoops, such as your eq method. However, one possibility is that you may have had a different case in ...
5
votes
Accepted
How to display downloaded PDF blob in an iframe?
You have to alter your getPDF() method and prepend data:application/pdf;base64,
public String getPDF() {
return 'data:application/pdf;base64,'+EncodingUtil.base64Encode([SELECT VersionData ...
5
votes
Accepted
Merging Docx files into one - Apex
Aside from plain text files (e.g. source code or README.TXT type files), most files follow an internal structure. This means that two similar files (e.g. two GIF or DOCX) being "added together&...
4
votes
Accepted
visualforce to create a attachment for an object
Declare an Id variable.
In the constructor, retrieve the Id of the record as follows:
controller.getId();
With this Id, try to insert the attachment record.
Change VFP code like this:
<apex:...
4
votes
Send Blob file via Apex Rest Callout
Proper multipart/form-data POST requests from Apex are tricky. As @sfdcfox mentioned, you need to do some very careful manipulations between the 8-bit bytes of the input file and the 6 bit groups used ...
4
votes
Why does a variable of blob type, when printed gives out it's size?
Use EncodingUtil.base64Encode for the contains for the Blob. Refer EncodingUtil Class
String str = 'myString';
Blob b = Blob.valueOf(str);
System.debug(b); //it returns Blob[8]
String base64String = ...
4
votes
Accepted
Convert Int Array to Blob
Apex doesn't have the notion of "byte arrays", unfortunately, so there's no one-liner that can do this. The best you can do if you start from this array would be something like:
Integer[] ...
3
votes
Accepted
How do I convert a Blob into an alphanumeric string and back?
Use EncodingUtil.base64encode to convert to a String, and base64decode to get back to a Blob.
3
votes
Accepted
How to view attachment content?
You can get the string value of a Blob using its toString method:
system.debug(a.Body.toString());
3
votes
Accepted
Trying to show the content field (blob) from contentNote in Visualforce
There are two ways to convert a Blob to a string in Apex. Depending on how the Blob was created, you'll use one or the other:
blobVar.toString();
encodingUtil.base64encode(blobVar);
For content, ...
3
votes
Merging pdf attachments
PDF is a binary format that, like most binary formats, simply can't be squashed together directly. It contains magic headers, object graphs, images, compression, and a bunch of other stuff that you ...
3
votes
Accepted
List out of bound exception at List<Blob>
Instead counter use b.size()
for(integer i = 0; i <b.size(); i++)
{
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachment.pdf');
efa.setBody(...
3
votes
Alternative to renderas PDF for converting an HTML to PDF in apex
There are a number of AppExchange packages that can generate a PDF using a template- Conga, Drawloop, and Thunderhead are three well known ones. Generally these templates are built in Word or another ...
3
votes
Accepted
Getting Blob data from content document using File Sync
The trigger can also be written on COntent Version .The content version object has field version Data and that holds data in base 64 encoded format .
https://www.salesforce.com/developer/docs/api/...
3
votes
Select body Of attachments
I know this is four months old, but I just ran into this myself, and may have a reason as to why this occurs. There is a very small blurb at the bottom of this page on the developers site :
You can ...
3
votes
Reading a pdf file in apex controller
If you mean you want to look at the bytes that make up the file using Apex code you can't directly. You can turn it into a base64 string using EncodingUtil.base64Encode but as the string characters ...
3
votes
Accepted
Send Blob file via Apex Rest Callout
Thanks for all of your valuable feedback. Below example worked for me with some modifications.
How can I compose a multipart/form-data request?
Here is my code.
File Upload Method
public void ...
3
votes
Accepted
Multipart form data post file with multiple form parameters?
I'd avoid manually handling the Base64 encoding yourself and the application of Grant Wickman's solution to avoid padding characters on the binary data before the multipart boundary.
I looked at this ...
3
votes
MD5 Blob Cannot Convert to String
This is a useful cryptography helper class I often use:
public class CryptoUtils {
public static String SHA1Hash(String value) {
return hash('SHA1', value);
}
public static ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
blob × 116apex × 62
attachment × 19
contentversion × 14
pdf × 13
visualforce × 9
rest-api × 9
javascript × 8
callout × 8
httprequest × 8
blob.topdf × 7
base64 × 6
unit-test × 5
string × 5
csv × 5
json × 4
class × 4
document × 4
crypto × 4
encodingutil × 4
lightning-aura-components × 3
trigger × 3
apexrest × 3
files × 3
contentdocument × 3