Upload Text File to View And Download Text File from View

To Upload to View.

I would:

  1. I would write the uploaded byte into tempFilePath:
	#creates a temporary file (with given extension) on host
	tempFilePath = system.file.getTempFile(fileExt)
	#write file byte to temporary file
	system.file.writeFile(tempFilePath, fileByte)
  1. How do I extract the file bite into json and write to custom property?

To Download, I would:

  1. Convert to bytes and download:
	system.perspective.download(filename, excelBytes)
  1. How do I convert jsonText to file?

Upload, assuming you're in the context of the File Upload component (because that's the only way to load a file into Perspective):

jsonString = event.file.getString()
json = system.util.jsonDecode(jsonString)

self.custom.myCustomProperty = json

Downloading is the inverse operation:

jsonString = system.util.jsonEncode(self.custom.myCustomProperty)
system.perspective.download(filename, jsonString, contentType="application/json")
1 Like