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
Kyle Sipila 1Kyle Sipila 1 

Web Service question

Okay, I am having a bit of trouble finding a solution to this predicament I am in and am hoping you guys can help me. I am trying to create a SalesForce web service that will recieve a file in the form of a byte array. The service will pass in the following paramters. Product Code, file name, and a byte array containing the contents of the file being submitted.

So, how would i go about coding this solution? I know how to do this in both C# and Java, but can't seem to find any example on how to do this with APEX code. What I think the process should be is to convert the byte array back into a FileStream, then store the doucment to SalesForce using the Document object. But I have not seen a constructor for the Document object that will take in either a byte array or a Stream object.

Any ideas?
Kyle Sipila 1Kyle Sipila 1
Matthews, not sure if you copied the wrong url, but the link you provided is in regards to interview questions and not quite what I was looking for.
AK VineethAK Vineeth
Hi Kyle ,,

There are lots of methods provided salesforce where we can convert byte to filestream , please refer below links ,Hope this helps you . 

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_restful_encodingUtil.htm



Cheers





AK VineethAK Vineeth
HI Kyle ,

Here is One more example in salesforce how we use the encoding util methods
String data='Testing data ';
Blob key = Crypto.generateAesKey(128);
 
Blob data = Blob.valueOf(data);
 
// It will encode in base 64
String b64Data = EncodingUtil.base64Encode(data);
 
// following will be use for Encrypt and Decrypt 

Blob encryptedData= Crypto.encryptWithManagedIV('AES128', key, data);
Blob decryptedData = Crypto.decryptWithManagedIV('AES128', key, encryptedData); 
 

//Converting the Blob into string 
String b64Decrypted = EncodingUtil.base64Encode(decryptedData);
Hope this might help you 

Cheers
Alex Mark 7Alex Mark 7
Please Visit Our Quizack Online MCQ Sites: https://quizack.com/
Alex Mark 7Alex Mark 7
Please Visit Our Quizack Online MCQ Sites: https://quizack.com/ (https://quizack.com/" target="_blank)
Alex Mark 7Alex Mark 7
Please Visit Our Quizack Online MCQ Sites: https://quizack.com/
Rakesh G 37Rakesh G 37
Entrar is India's most integrated and customizable school management software (https://entrar.in/school-management-software.html) that not only connects every stakeholder's needs seamlessly but also to the offline and online learning worlds.