Announcement

Collapse
No announcement yet.

file content truncated

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • file content truncated

    I have a database reader channel + file reader transformer => file writer destinations.
    I read various contents and file names from the database, including the source path and output filename of a pdf.
    In the source transformer, I'm reading the contents of the pdf from the file system to add to the channel map.

    The test pdf I'm using is about 700k. The javascript code below is the transformer step.

    The FileUtil.readBytes method seems to successfully read the whole file, as the logger records the correct length of the byte array. However the output variable is only 6 bytes long and this is what is being written by the file writer (binary mode).

    Is there something I'm missing? I've attached the channel definition.
    Thanks

    Code:
    var mapping;
    
    try {
    	if (msg['sourcepathpdf'].toString()!='') {
    		mapping = FileUtil.readBytes(msg['sourcepathpdf'].toString());
    		logger.info('File length: '+mapping.length);
    	}
    }
    catch(e) {
    	logger.error(e);
    	mapping = '';
    }
    
    channelMap.put('contentPdf', mapping);
    Attached Files
    Last edited by Colizobble; 02-20-2016, 01:09 AM.

  • #2
    I've found the answer myself.
    I just needed to encode the binary array before putting the content on the channel map:

    Code:
    var mapping;
    
    try {
    	if (msg['sourcepathpdf'].toString()!='') {
    		var content = FileUtil.readBytes(msg['sourcepathpdf'].toString());
    		mapping=FileUtil.encode(content);
    	}
    }
    catch(e) {
    	logger.error(e);
    	mapping = '';
    }
    
    channelMap.put('contentPdf', mapping);

    Comment

    Working...
    X