Post to webdev using file upload component

Is there a way to save a pdf from a view to webdev using the file upload component? I was trying to use the system.file.writeFile command and it said it was successful (no errors) but the file never showed up.

code used was
filename - event.file.name
filebytes = event.file.getBytes()
system.file.writeFile("/system.webdev/projectname/"+filename, getbytes)

If you’re referring to the File Upload component, the only “success” or “failure” it is aware of is whether or not the file was read in by the component successfully. The component has no insight into the success of any attached scripts.

If you examine the Gateway logs, I suspect you’ll either find a script exception for your code, or you’ll find that the code succeeded and wrote the file to some location you didn’t expect.

What I recommend in situations like this is to have a neighboring component reflect the status of the script. I like to have an Icon next to my File Upload component and within my onFileReceived Event I will change the color or path of the icon to reflect a successful completion as the final step.

1 Like

I had a system.perspective.print(“loaded”) statement at the end of the code and it printed fine (sorry it wasn’t included I had to type out all the code because it’s on another server). As for the path I copied the mounted path from one of my pre-exsisting files and just changed the file name to filename. What other locations could it be saved?

Try placing this into a Button as part of the onClick Event (and obviously replace the projectname and filename parts):

text = 'Missing'
if system.file.fileExists("/system/webdev/projectname/"+filename):
    text = 'Exists'
self.props.text = text

Or you could use the fileExists piece in your current code to verify success and report that during your print statement.

So I got it to save to the correct location “C:/Program Files/InductiveAutomation/Igntition/data/projects/projectname/com.inuctiveautomation.webdev/resources/” but how do I format the pdf so that it’s readable by webdev. When it’s saved though webdev it saves as a folder with config.json, file.bin, and resource.json in it. How do I format a pdf into this folder format (through scripting)?

Why are you trying to save the uploaded file as a file resource? Use a database to store it, and use a single Python resource handler to retrieve it if you need to.