Hi everyone! I have an SSS_FILE_CONTENT_SIZE_EXCE...
# suitescript
n
Hi everyone! I have an SSS_FILE_CONTENT_SIZE_EXCEEDED error when I use file.getContents() function for a binary file which is larger 10 Mb (it is just a big jpeg image) https://netsuite.custhelp.com/app/answers/detail/a_id/43539 However, I need to send this file outside Netsuite with an http POST request. I tried to load the file by chunks with file.reader.readChars ( https://netsuite.custhelp.com/app/answers/detail/a_id/82487) like this
while (chunk = file.getReader().readChars(1000)) { postBody += chunk }
and it even works, but I don't know what to do next to get a normal base64 encoded jpeg file from this 'postBody' variable. Is it possible at all? This variable looks like '����JFIF��C' when I try to output it in the browser. It looks like the current 'postBody' variable is encoded somehow too, maybe it is a hex representation of the binary file, I don't know. Do you have any ideas how to send a binary file which is larger 10Mb from Netsuite file cabinet via http POST request? Thanks.
w
What do you mean by "normal" base64-encoded JPEG? JPEG is a binary format.
If you're expecting to see the image, it sounds like your postBody var has the right contents ('JFIF' in binary gibberish is what I'd expect at the start of a JPEG) but you're not setting a Content-Type header so the browser is trying to interpret it as a text file.
n
when I tried to base64 encode this string with N/encode, then send it in POST body, then decode it back to binary and save the file, the file cannot be read as an image. I did the same with the smaller files - file.getContents() was used because the filesize allowed that, sent it via POST, decoded, saved, and the image was ok. But when I did use readChars function instead of file.getContents, the generated file is corrupted..
w
Corrupted in what way? What do you get if you download the file manually from the file cabinet and then compare the two?
n
it is a binary file too but the data is different
w
Different in what way? Are the files the same size? Do they contain any of the same data?
n
thanks, I'll try to compare and let you know
The structure of the file content is exactly the same, but all characters are wrong - there are '�����Y�' instead of '–‡ЌЂщЫзY¶' characters in the normal jpeg file (see the screenshot). It looks like my encoding is wrong. Here is how I encode it before sending it:
Copy code
var hexEncodedString = ''
				var reader = netsuiteFile.getReader()
				var chunk;
				while(chunk = reader.readChars(1000)) {
					hexEncodedString += chunk
				}
				payload = encode.convert({
				    string: hexEncodedString,
				    //inputEncoding: encode.Encoding.HEX,
				    inputEncoding: encode.Encoding.UTF_8,
				    outputEncoding: encode.Encoding.BASE_64
				});
This is the testing jpeg image
This is what is generated by Netsuite when I do the following: upload the file via suitelet form and then
Copy code
var netsuiteFile = context.request.files['uploadfileformfield']
				var hexEncodedString = ''
				var reader = netsuiteFile.getReader()
				var chunk
				while(chunk = reader.readChars(1000)) {
					hexEncodedString += chunk
				}
				var Newfile = file.create({
				    name: 'test-after.jpg',
				    fileType: file.Type.PLAINTEXT,
				    contents: hexEncodedString,
				    encoding: file.Encoding.UTF_8,
				    folder: 30,
				}).save()
The filesize is twice bigger then the original file.
When I try to save the content after reader.readChars as a JPEG image I get an UNEXPECTED ERROR:
Copy code
var Newfile = file.create({
				    name: 'test-after.jpg',
				    fileType: file.Type.JPGIMAGE,
				    contents: hexEncodedString,
				    folder: 30,
				}).save()
So I assume reader.readChars converts my binary to a plaintext string and it is impossible to get a normal binary representation of it, isn't it?
w
Probably readChars() is returning surrogate pairs and mangling the binary data, yes.
Is there a reason you can't send the file directly using ServerResponse.writeFile() ?