@paul-griffith, 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))
dataList.append('')
metadata = system.file.readFileAsString('/usr/local/bin/ignition/webserver/webapps/main/metadata.json')
dataList.append(metadata)
#PDF file
dataList.append('--' + boundary)
dataList.append('Content-Disposition: form-data; name=""; filename="{0}"'.format(event.file.name))
fileType = mimetypes.guess_type(event.file.name)[0] or 'application/octet-stream'
dataList.append('Content-Type: {}'.format(fileType))
dataList.append('')
dataList.append(event.file.getString())
dataList.append('--'+boundary+'--')
dataList.append('')
body = '\r\n'.join(dataList)
payload = body
self.getSibling("txt_requestBody").props.text = payload
uri = 'https://www.googleapis.com/upload/drive/v3/files'
headers = {'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Bearer ' + access_token, 'Content-type': 'multipart/form-data; boundary={}'.format(boundary)}
resposnse = system.net.httpClient().post(uri, data=payload, headers=headers)
logger = system.util.getLogger("myLogger")
logger.info(str(resposnse))
Original PDF file opened in Notepad:
Uploaded file:

