Need help writing and image file to a mapped drive on the gateway

I have a project where users can upload an image that gets stored to both a SQL database, and to a drive on the gateway. Later, we use a mounted folder to serve the images that are stored on the drive. Then we display those images in a web page created by a WebDev, python resource. For reasons I won' t go into, we don't want to pull these images from the database for display.

All of this works fine if the drive is local to the gateway. We prefer not to store the images directly on the gateway's drive though as we don't want to use space on the VM for this reason. We would prefer to map a drive on the gateway to a NAS and store the files on the mapped drive. This is where the problem arises.

When we run this script on the upload component (in Perspective):

def runAction(self, event):
fileName = event.file.name
#path = "C://ExpenseReceipts/" + fileName
path = "X://expenseReceipts/" + fileName
system.file.writeFile(path, event.file.getBytes())

The commented line to the C:\ drive above works like we expect. The uncommented line to the X:\ drive does not. The X:\ drive is the mapped drive.

Both of these drives have been created as WebDev mounted folders.

The error returned in the log is:

Error running action 'component.onFileReceived' on JMS/Expenses/test@C/root/FileUpload: Traceback (most recent call last): File "function:runAction", line 5, in runAction IOError: Unable to create path to file 'X:\expenseReceipts\myFile.pdf'

Add the map to the Ignition conf, this will require a reboot to take effect

https://docs.inductiveautomation.com/display/DOC81/Mapping+a+Network+Drive

2 Likes

Note that if your NAS is not available at the time Ignition starts or restarts, it won't ever connect without another restart.

Mapping network drives for background services is a kludge.

You should revisit this, or:

Put a reverse proxy in front of Ignition that can divert requests for the folder of images to another webserver that has direct access to the files.

Or, switch to an operating system that can provide network filesystems to background services without drama.

You could also use a UNC path instead of a mapped drive

1 Like

I completely forgot this step. Thank you! We can now write to the share.