I agree with you i explore the data stream way,so i test a piece of code for use a data stream with a cloud location (data management).
The attachement is succeed (docuref and cloud url created) but when i check the file result from the web client with open file , there is no data in it :(
System.IO.Stream stream;
TextStreamIo textStreamIo;
container cLine;
DocuRef addedRecord;
CustTable custTable;
FileName fileName;
str fileContentType;
fileName = "TESTDocu.csv";
fileContentType = "text/csv";
custTable = custTable::find("TEST");
if(custTable)
{
try
{
ttsbegin;
cLine = conNull();
cLine = conIns(cLine,1,"MyDataLine1"); // One line of data
textStreamIo = TextStreamIo::constructForWrite(1252);
textStreamIo.outFieldDelimiter('');
textStreamIo.outRecordDelimiter('\r\n');
textStreamIo.write(cLine); // Add data to stream
//textStreamIo.writeRaw("Test2");
textStreamIo.finalize();
stream = textStreamIo.getStream();
// DocumentManagement add
addedRecord = DocumentManagement::attachFile( custTable.TableId,custTable.RecId,custTable.DataAreaId, 'FlatFile', stream, fileName, fileContentType,"Csv file attached");
if(!addedRecord)
{
throw error("Failed to attach");
}
ttscommit;
}
catch (Exception::UpdateConflict)
{
throw Exception::UpdateConflict;
}
catch (Exception::DuplicateKeyException)
{
throw Exception::DuplicateKeyException;
}
catch (Exception::Deadlock)
{
throw Exception::Deadlock;
}
catch
{
throw error("Treatment failed");
}
info("End process");
}
}