system.file.writeFile to Mounted Folder in WebDev

Hello all
I just found WebDev and have been familiarizing myself with how it works, particularly around GET and Post commands. I am currently trying to make a post command save a passed in file to a mounted folder.

I am passing in both the byte array and file name using json passing, building the destination URL from the file name, and passing it to system.file.writeFile() with append false. No errors are thrown, and doing system.file.fileExists() on the url returns true, so something is saving, but navigating to the file location outside of ignition (using file explorer) shows an empty folder. All of this is inside a doPost python page in WebDev. The print(url) works as well

Any help is greatly appreciated
Thank you

	data = request["data"]
	fileName = data["fname"]
	file = data["fbytes"]
	
	
	projectName = system.project.getProjectName()
	
	url = "/system/webdev/%s/Files/" %(projectName) #+ fileName
	
	system.file.writeFile(url, file, False)
	
	print( url)
	
	
	
	return {'response': fileName + " received"}

You’re conflating two things, in a way that I think is leading to some confusion.

system.file.writeFile is a function that doesn’t know or care about the Webdev module.
The first parameter you give it is the location to save the file. You’re passing an intermediate URL path, not an actual filepath. The path parameter should be a fully qualified filesystem path. It probably is writing somewhere, just not the location you expect.

Thank you for your help with that issue. I still have a problem though with writing as it now throws an IO Error

IOError: File 'C://Users/[USERNAME]/Documents/ignition_mount/DRI_Office_Streetview_01_2021-11-30_01:35:59.jpg' doesn't exist or isn't a file.

Shouldn’t write be putting the file there? It does not exist, that’s why I want it saved. Not including the file name results in a not a file error, so it is at least seeing the folder structure.

	data = request["data"]
	fileName = data["fname"]
	file = data["fbytes"]
	
	
	projectName = system.project.getProjectName()
	
	url = "C://Users/[USERNAME]/Documents/ignition_mount/" + fileName
	
	print( url)
	
	system.file.writeFile(url, file, False)
	
	return {'response': fileName + " received"}

The actual error returned could be a red herring (Java has limited access to OS level error codes for file operations). Do all the intermediate directories exist, besides the file in question? Does the user/account the Ignition gateway is running as actually have access to that user directory?

I suspect it’s the latter; a permissions issue masquerading as a different error; try changing (via Windows Service’s dialog) the Ignition Gateway service to run as your user as a test (requires a restart of Ignition) and attempt the write.

1 Like

All directories exist save for the file. I changed the gateway service over to log on as “this account” with my credentials rather than “Local System Account”. I restarted the gateway service as well. Same error as before though. Ignition is running local on my machine if that helps.

Does windows allow colons in file names?

3 Likes

colons are invalid in windows filenames

That was it! Thank you for all your help everyone!