system.file.writeFile working from Script Console but not on button click

I have a weird issue I’ve been dealing with for the past couple days. I’m using a file upload component to upload a file onto a server (bypassing a horrible file upload interface in a web application). The filename is of this format:

//SERVER-NAME/Path/filename.pdf

where filename.pdf is the name of the uploaded file. The UNC path //SERVER-NAME/Path is added to the ignition.conf file.

I tried to run a simple script in the Script console to troubleshoot, but the file wrote successfully from the Script Console. Here is the sample script which worked correctly:

bytes = bytearray(b'HELLO WORLD')
filename = '//SERVER-NAME/Path/testdoc.pdf'
system.file.writeFile(filename, bytes)

I don’t know why a button press doesn’t yield the same result. When I log the exception that is thrown, it says

"File '//SERVER-NAME/Path/testdoc.pdf' doesn't exist or isn't a file"

What could be the problem?

If it’s running on a Perspective button the big difference is that when executed in the script console it’s running on your computer as your user in the Designer process, and when executed from a button press it’s executing on the gateway as whatever user the Ignition service uses.

3 Likes

So then the issue is likely how I added a network path to ignition.conf, right?

Yes, probably something to do with that.

I’m looking in the wrapper.log file and I see the message

Unable to create path to file '//10.1.20.11/Blinfo/Links/REQUISITION_QUOTES/filename.pdf'

What does this error message mean?

Seems like a permissions issue. Whoever is trying to write filename.pdf doesn’t have permissions on that network share to create the specified path.

//10.1.20.11/Blinfo/Links/REQUISITION_QUOTES/filename.pdf

That isn’t necessarily true… End users don’t write to the share if they use a Perspective session (with a button and a file upload component). The server that hosts Ignition will write to the remote directory. I added authentication for the file share to the ignition.conf file and made sure the folder permissions were set correctly. I also made sure to share the directory with the user I added (and made sure the user / password combination was still valid).

That is what I understand from reading the docs, I may be incorrect.

Maybe this doesn’t matter, but shouldn’t all those forward slashes be back slashes?

and what logger was responsible for that error message?

1 Like

I'm referring to who is running Ignition Service on the Ignition server.

I think you have to make sure the Ignition Gateway server account has permissions to write to your network share.

EDIT:
The above doesn't seem required.

You should be able to achieve the same with these configs:
image

@PGriffith; could you confirm this edit?

1 Like

I assumed you added a network drive path as well? Do you get any print statements in the wrapper regarding a successfully mapped drive?

I'm pretty sure it's one or the other, yeah. For what it's worth, I've always had more success using the wrapper args approach - theoretically making the service run as a user should give it permissions, but I haven't had a lot of luck with that.

1 Like

Here is the ignition.conf entry I added:

wrapper.share.2.location=\\10.1.20.11\Blinfo\Links
wrapper.share.2.target=P:
wrapper.share.2.type=DISK
wrapper.ntservice.account=<my_domain>\<username>
wrapper.ntservice.password=<my_password>
wrapper.share.2.account=<my_domain>\<username>
wrapper.share.2.password=<my_password>

Here is (essentially) how I use system.file.writeFile():

bytes = bytearray(b'HELLO WORLD')    # bytes is an uploaded file
# Notice how REQUISITION_QUOTES is a subdirectory of `Blinfo/Links`
filename = '//10.1.20.11/Blinfo/Links/REQUISITION_QUOTES/<filename>'
# What else I tried
#      filename = 'P:/REQUISITION_QUOTES/<filename>'
system.file.writeFile(filename, bytes)

Maybe it will serve me well to stop and start the Ignition service. As you can imagine, this isn’t the best option.

If you never restarted it after adding those entries then there is no chance they will have been in effect.

Also consider the forward vs back slashes.

I did stop and start it before, but that was a while ago. Nothing has changed since then, but I might wait for a break to restart it.

Regarding the slashes, I use forward slashes singularly and if I use back slashes, they’re doubled up (because the first one escapes the character that follows it). I tried almost every combination.

Also, something I forgot to mention is that I can go to the Explorer on the Ignition server and I can put in \\10.1.20.11\Blinfo\Links and browse the folder. So it is reachable and the directory is shared.

Restarted the service and now working again… Thanks Kevin

1 Like