I’m trying to download a PDF, but when I open it everything is blank.
If I open it with notepad and compare it with the original PDF, that’s almost right. I think the error is because of the encoding.



In the bottom right corner of the notepad is always UTF-8 when I download it, how can I change this?

My code:

    access_token = 'ya29.a0Af...'
	uri = ''
	headers = {'Authorization': 'Bearer ' + access_token}
	file = = uri, headerValues = headers)'SPM AWS.pdf',file, "application/pdf")

The problem is probably with httpGet, not - once you’re downloading the file, there’s no encoding.

Since you’re already in 8.0, I would highly recommend migrating to
Unlike httpGet, it will try to use the charset from the Content-Type header in the response - and if one is not found, it falls back to UTF-8, instead of the platform’s default charset (which is UTF-8 on basically every platform except Windows), as does.

It would be a drop in replacement for the existing code you have:

uri = ''
headers = {'Authorization': 'Bearer ' + access_token}
file =, headers=headers).body
# file = = uri, headerValues = headers)
1 Like


Worked perfectly.
Thank you very much!

@PGriffith, I am facing a very similar problem right now, but when I upload a file, could you help me?

I’m using the ‘File upload’ component in perspective, trying to upload a file to Google Drive.
The file arrives in the Google Drive folder, but with the wrong encoding.

onFileReceived script event:

	import mimetypes
	access_token = self.getSibling("txt_accessToken").props.text	
	dataList = []
	boundary = 'wL36Yn8afVp8Ag7AmP8qZ0SA4n1v9T'
	#Metadata file
	dataList.append('--' + boundary)
	dataList.append('Content-Disposition: form-data; name=""; filename="{0}"'.format('/usr/local/bin/ignition/webserver/webapps/main/metadata.json'))	
	fileType = mimetypes.guess_type('/usr/local/bin/ignition/webserver/webapps/main/metadata.json')[0] or 'application/octet-stream'
	dataList.append('Content-Type: {}'.format(fileType))
	metadata = system.file.readFileAsString('/usr/local/bin/ignition/webserver/webapps/main/metadata.json')
	#PDF file
	dataList.append('--' + boundary)		
	dataList.append('Content-Disposition: form-data; name=""; filename="{0}"'.format(	
	fileType = mimetypes.guess_type([0] or 'application/octet-stream'
	dataList.append('Content-Type: {}'.format(fileType))
	body = '\r\n'.join(dataList)
	payload = body
	self.getSibling("txt_requestBody").props.text = payload
	uri = ''
	headers = {'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Bearer ' + access_token, 'Content-type': 'multipart/form-data; boundary={}'.format(boundary)}
	resposnse =, data=payload, headers=headers)
	logger = system.util.getLogger("myLogger")

Original PDF file opened in Notepad:

Uploaded file:

Is implicitly using the default charset. Add "UTF-8" to the getString() call.

Why are you not using .getBytes() if you are just saving the file to the filesystem? Converting from bytes to string back to bytes is not guaranteed to be idempotent.

I added the charset parameter, but I’m still getting the encoding error


But I am not saving to the file system.
I’m trying to upload the file via HTTP to the Google Drive API

You should be constructing your upload with binary (probably base64) encoding of the bytes, not a string. PDFs have binary content and will not decode/reencode properly as strings.

1 Like

Ah, yeah, Phil’s right. You need to retrieve the bytes and encode them yourself into base64 to place into the multipart/form-data you’re building.

I made the following attempts:


but none of them worked …