function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
nandurinanduri 

Convert JSON data stored in SFDC to Image JPEG file

I have one task that is assigned to me i.e, Convert JSON data (JSON representation of an image) that is stored in Salesforce.com to an actual image and store it as an attachment to the same record.

 

I have the java code for this, but is there any way of doing this with salesforce.com directly, if yes, can anyone help me, giving some direction as what needs to done.
 
Data is being transmitted in JSON is not via base64
 
Example of the JSON data that is being stored in Salesforce.com 
 
[{"lx":12,"ly":15,"mx":12,"my":14},{"lx":13,"ly":14,"mx":12,"my":15},{"lx":14,"ly":14,"mx":13,"my":14},{"lx":14,"ly":15,"mx":14,"my":14},{"lx":15,"ly":15,"mx":14,"my":15},{"lx":16,"ly":15,"mx":15,"my":15},{"lx":17,"ly":15,"mx":16,"my":15},{"lx":18,"ly":16,"mx":17,"my":15},{"lx":19,"ly":17,"mx":18,"my":16},{"lx":20,"ly":17,"mx":19,"my":17},{"lx":21,"ly":17,"mx":20,"my":17},{"lx":22,"ly":18,"mx":21,"my":17},{"lx":23,"ly":18,"mx":22,"my":18},{"lx":24,"ly":18,"mx":23,"my":18},{"lx":25,"ly":18,"mx":24,"my":18},{"lx":26,"ly":18,"mx":25,"my":18},{"lx":26,"ly":19,"mx":26,"my":18},{"lx":27,"ly":20,"mx":26,"my":19},{"lx":28,"ly":20,"mx":27,"my":20},{"lx":29,"ly":20,"mx":28,"my":20},{"lx":30,"ly":20,"mx":29,"my":20},{"lx":30,"ly":21,"mx":30,"my":20},{"lx":31,"ly":21,"mx":30,"my":21},{"lx":32,"ly":21,"mx":31,"my":21}]
 
 
 
 
sfdcfoxsfdcfox

I would imagine that any image over approximately 140 x 140 (20,000 pixels) wouldn't be possible due to the number of script statements required. That said, I suppose it would be possible to do the following:

 

1) JSON.decode into a custom object/object list.

2) Loop through the object list and render the individual pixels to a Base64 string stream.

3) Decode the base 64 string into a Blob.

4) Save the file as an attachment/document/etc.

AmbilyAmbily

Hi,

 

Were you able to solve this? If yes how?

 

I am also in a situation to do the same.

 

Thanks

Ambily