Good evening Forum,
 
I'm looking for a way to extract several files contained in a binded rich text field onto the file system (on a network share)
 
I don't want user interaction, just click a button to extract / create the files, no popup to allow download....
 
I think I can do something with the next piece of code: 
 
	var inPath:string = requestScope.filepath;
	var n:int = inPath.lastIndexOf(".");
	var outPath:string = inPath.left(n) + "Copy" + inPath.right(inPath.length - n);
	var inStream:NotesStream = session.createStream();
	if (inStream.open(inPath, "binary")) {
		if (inStream.getBytes() > 0) {
			var outStream:NotesStream = session.createStream();
			if (outStream.open(outPath, "binary")) {
				if (!outStream.isReadOnly()) {
					do {
						var buffer = inStream.read(32767);
						outStream.write(buffer);
					} while (!inStream.isEOS());
				} else requestScope.status = "Output file exists and is read-only";
				outStream.close();
			} else requestScope.status = "Output file open failed";
		} else requestScope.status = "Input file has no content";
		inStream.close();
	} else requestScope.status = "Input file open failed";	
 
 
I already use something similar with HTML text contained in an edit box that I create a file from. Also using outStream.writeText.
 
So I don't think it's possible to extract the files without having to user accept the download, but It should be possible to convert to files to binary and write them like I already do for the HTML content. 
 
I hope someone will be able to help me with this? 
 
Thanks in advance, 
 
Chris 
 
======================================= 
 
Hi Forum, 
 
In the meantime I continued testing and next code bring me close to what I need, except that the created file doesn't have the right content... Probably problem with the buffer.
 
var strId:String = "2F509C8CD8D5F9A6C125789D0066DD06";
var strFile:String = "image.gif";
//retrieve target document from current database
doc = database.getDocumentByUNID(strId);
var eo:NotesEmbeddedObject = doc.getAttachment( strFile );
strFile = eo.getName();
var outPath:string = "\\\\Server\\XXX\\XXX\\"; //Path for output
var cdir = new java.io.File(outPath);
if (cdir.exists()) {
	var outFileName:String = strFile;
	var fos = new java.io.FileOutputStream(outPath + outFileName);
	var osw = new java.io.OutputStreamWriter(fos);
	var outputStream:NotesStream = session.createStream();
	
	var buffer = new byte[4 * 1024];	// 4K buffer
	var bytesRead;
		
	var bufferedIS = new java.io.BufferedInputStream( eo.getInputStream());
	
	while ((bytesRead = bufferedIS.read(buffer)) != -1) {
		//outputStream.write(buffer, 0, bytesRead); //Error
		outputStream.write(buffer);
	}
	
	outputStream.getContents(osw);
	osw.close();
	bufferedIS.close();
	eo.recycle();
	outputStream.close();
} 
 
 
Thx in advance for the assistance. 
 
Chris