You need to sign in to do that
Don't have an account?
samthakur74
Creating a blob representation of a csv file on my machine
Hello,
Can anyone tell me how to create a blob representation of csv file on my machine using Apex code? I am trying to upload a csv file programmatically using Apex custom class. I am using custom classes installed by product AWS s3 which i have installed on SalesForce. I am calling the function syncFilesystemDoc in AWS_S#_ExampleController.cls. To use this correctly i need to populate fileblob which is where i am stuck
regards
Sameer
Hello,
I realized my approach was incorrect. I do not need to read a csv and create a blob. I can just create a string of the record i want to save , then use Blob.valueOf(String) and use S3 api decribed above
regards
Sameer
All Answers
can you share corresponding part of code?
Sure. Thanks for responding. This is the method which i am trying to call from my Custom class. Its part of class AWS_S3_ExampleController which gets installed with AWS S3 toolkit on SalesForce.
Its not necessary i use this. I need any solution which allows me to read a csv file into a String. The conversion to blob is easy enough. I do not want a UI solution as my custom class does not have a UI
/*
This method uploads a file from the filesystem and puts it in S3.
It also supports setting the Access Control policy.
*/
public pageReference syncFilesystemDoc(){
try{
Datetime now = Datetime.now();
String docBody = EncodingUtil.base64Encode(fileBlob);
//TODO - make sure doc.bodyLength is not greater than 100000 to avoid apex limits
System.debug('body length: ' + fileSize);
uploadObjectErrorMsg = 'Error';
Boolean putObjResult = as3.PutObjectInline_ACL(bucketToUploadObject,fileName,null,docBody,fileSize,accessTypeSelected,as3.key,now,as3.signature('PutObjectInline',now),as3.secret, OwnerId);
if(putObjResult==true){
System.debug('putobjectinline successful');
uploadObjectErrorMsg = 'Success';
}
}catch(System.CalloutException callout){
System.debug('CALLOUT EXCEPTION: ' + callout);
uploadObjectErrorMsg = callout.getMessage();
}catch(Exception ex){
System.debug('EXCEPTION: ' + ex);
uploadObjectErrorMsg = ex.getMessage();
}
return null;
}
Hello,
I realized my approach was incorrect. I do not need to read a csv and create a blob. I can just create a string of the record i want to save , then use Blob.valueOf(String) and use S3 api decribed above
regards
Sameer