I've a small javascript "upload" webscript (alfresco version: 3.4.d) to receive and parse base64 encoded document content in an XML tag, like this:
<request>
<officeName>office_0001</officeName>
<worksheetId>worksheet_0001</worksheetId>
<documentName>document_0001.txt</documentName>
<documentMimetype>text/plain</documentMimetype>
<documentContent>aGVsbG8gd29ybGQh</documentContent>
</request>
After parsing of documentContent XML tag, base64 decoder results a string with decoded binary data (contentData.lenght same as original binary length):
logger.log(serviceName+": decoding base64 data, size: "+documentContent.length);
var contentData = Base64x.decode(documentContent);
logger.log(serviceName+": base64 data decoded, size: "+contentData.length);
And next the problematic part; the contentData in newDocumentNode.content is bigger than contentData.length, looks like UTF-8 encoded (newDocumentNode.size not matched with contentData.length)…
var newDocumentNode = worksheetFolderNode.createFile(model.documentName);
if (newDocumentNode != null) {
newDocumentNode.content=contentData;
newDocumentNode.save();
logger.log(serviceName+": new document size: "+newDocumentNode.size);
}
Runtime log:Size of original data before base64 encode: 5921
Test with PHP's utf8_encode: UTF-8 size of binary data: 8870
18:29:17,503 User:admin DEBUG [repo.jscript.ScriptLogger] upload: decoding base64 data, size: 7896
18:29:17,536 User:admin DEBUG [repo.jscript.ScriptLogger] upload: base64 data decoded, size: 5921 (SAME AS ORIGINAL SIZE)
18:29:17,590 User:admin DEBUG [repo.jscript.ScriptLogger] upload: new document size: 8870 (LOOKS LIKE UTF-8 ENCODED SIZE)
How can i write node's content without encoding base64 decoded string?Is it possible to use java-side base64 decoder from javascript webscipt? Somebody could post an example?