Write - base64 decoded - binary content without encoding
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-03-2011 03:07 AM
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:
After parsing of documentContent XML tag, base64 decoder results a string with decoded binary data (contentData.lenght same as original binary 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)…
Runtime log:
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?
<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: 789618: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?
Labels:
- Labels:
-
Archive
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-09-2011 05:52 PM
Did you try to set the correct mimetype before you put the content into newDocumentNode? newDocumentNode.mimetype = xxx;
