Hitachi Vantara Pentaho Community Forums
Results 1 to 5 of 5

Thread: Salesforce Attachment Write to Binary File - Javascript using java.io.File

  1. #1
    Join Date
    Mar 2015
    Posts
    7

    Default Salesforce Attachment Write to Binary File - Javascript using java.io.File

    i am trying to read data from the Attachments sobject in Salesforce.

    I have tried with an without a step to base64 decode the Body of the Attachment record from Salesforce.

    I have tried to follow this blog http://type-exit.org/adventures-with...lobs-to-files/ which was mentioned in this thread http://forums.pentaho.com/showthread...ry-blob-export a while back but I keep getting an error with

    "InternalError: Cannot convert <the file content> to java.lang.Integer (script#23)"

    At the step "Write Blob content to Transformation Dir" which has this code

    Code:
    // pseudo import
    var File = java.io.File;
    var FileOutputStream = java.io.FileOutputStream;
    var BufferedOutputStream = java.io.BufferedOutputStream;
    
    
    // output variables
    var success;
    var message;
    
    
    // determine filename and content, strip off "file://" from path
    var filename = substr(getVariable('Internal.Transformation.Filename.Directory', '') +'/'+file_name, 7);
    var outBytes = file;
    
    
    try{
    	var f = new File(filename);
    	
    	if (!f.exists()){
    		f.createNewFile();
    	}
    
    
    	var fos = new FileOutputStream(f);
    	var bos = new BufferedOutputStream(fos);
        bos.write(outBytes);
    	bos.flush();
    	bos.close();
    	
    	success = 'Y';
    	message = 'OK';
    
    
    }
    catch (e){
    	success = 'N';
    	message = e.javaException.toString();
    }

  2. #2
    Join Date
    Mar 2015
    Posts
    7

    Default

    I had to comment out this line to get the transform to run at all or else I would get an error that e.JavaExeception is not defined

    message = e.javaException.toString();

  3. #3
    Join Date
    Mar 2015
    Posts
    7

    Default

    some more findings with curl


    text file


    curl https://myinstance.salesforce.com/se...0bEKeVEAW/body -H 'Authorization: Bearer <my session>' >> revenue.txt


    picture.jpg


    curl https://myinstance.salesforce.com/se...0bEO8hEAG/body -H 'Authorization: Bearer <my session>' >> picture.jpg

    both of these will result in a proper file being written with no other changes needed.

    I am able to get this to work in rest client in pentaho but writting the file is the problem.

  4. #4
    Join Date
    Mar 2015
    Posts
    7

    Default

    per salesforce http://www.salesforce.com/us/develop...inName=webhelp

    Example response bodyAttachment body content is returned in binary form. Note that the response content type will not be JSON or XML since the returned data is binary.



    So how can one read binary done over HTTP and write to file in pentaho?

  5. #5
    Join Date
    Mar 2015
    Posts
    7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.