File Upload Perspective

Hi everyone,

I need some helps with the file upload component, even with the doc i don’t understand how it work.

I need this component for uploading a picture from my tablet to send it to some one else.

Somebody can explain me how this component work ?

Actualy I tried to use the " onFileReceived " event with event.file.copyto but I’m stuck.

1 Like
upload_path = 'webserver/webapps/main/'
system.util.getLogger('FILEUPLOAD').info('Uploading: \'{0}\' to directory \'{1}\''.format(event.file.name, upload_path))
event.file.copyTo(upload_path + event.file.name)

will place a file directly into the Inductive Automation\ignition\webserver\webapps\main directory of your Gateway.

Assuming you upload a file to that destination, you can then locate that file (in the same script) with

system.file.fileExists(upload_path + event.file.name)

If you were to upload an image with a file name of “filename.jpeg”, for example, then you would then point to that file in an Image component with /filename.jpeg.

5 Likes

Thanks you a lot !

There is a component or a method which allow me to take a picture from my tablet camera (by the way is not an android tablet) ?

We do not currently have any way for Perspective to take a picture with a mobile device (outside of scanning a barcode, which does not actually save a file to your device). A “Picture” action is something we’re considering in later versions, but it’s not even in a planning stage yet.

1 Like

Although, at least some browsers (mobile Safari in particular I know does this) allow you to directly take a picture when prompted to upload a file. It’s up to your device and browser whether to prompt for this, so it’s worth trying different browsers and looking into device settings.

Thanks, but i will look if with my windows 10 tablet i can have this.

Any updates/ plans to make this a feature in the app?

To make what a feature in the app?

@cmallonee
the folders/directories in webserver\webapps\main seems to be forbidden to acces in the browser (error 403) i can acces the images inside it, but i would also like to acces the whole folder itself
is there somewhere where i can allow it? (some htacces config or something?)

in the webserver/webdefault servlet file the dirAllowed is already true so not sure where else it could be

edit:
ah nvm i found it
webserver\webapps\main\WEB-INF\web here it stood on false

Hi @cmallonee
I use your code and it work perfectly the only problem is the image component cache the old image and if I change the image it show the old one always.
It seems perspective cache every thing. Is there any way to disable caching for image component?

I am curious if there is a way to get the file path from this component. This way It would be easier for the users, and it would be less changes to code I already have set up.

Currently I am storing the contents of the file in a custom tag property on the main view, then I can read it in that way. But I do not like having to import two libraries if I can help it.

def runAction(self, event):
	import csv
	import io
	
	fileContents = self.view.custom.csvFileContents
	
	csvFile = io.StringIO(fileContents)
	csvReader = csv.DictReader(csvFile, delimiter = ',')
	for colHeader in csvReader:
	    system.perspective.print(colHeader['UDTDefPath'])

Edit:
I know I can get it from the gateway but I am not trying to save the files there. Sorry should have clarified this.

What file path? From the client browser? That would be a security hole in the browser.

If you mean the folder path in the gateway, then it is always a temporary folder, and the file name used in that folder is not under your control. If you don't handle the file in the uploaded event with the supported accessors, the content will be discarded.

It is wise to put the file somewhere other than gateway RAM if uploads are expected to be large. (Perspective properties all use gateway RAM.)

2 Likes

Expect a better first party solution for this in 8.3.

2 Likes

Oh that's cool!

As of now when I/others need to make an edit using a CSV file I made a text component and just read the file path from that component into the csv python with open() aspect. I just hold shift on the file then right click and select copy as path to get:

"C:\temp\mods2.csv"

pic example:
image

For the browser side source path?

For the use case of "I want to store files uploaded via Perspective in a well known, configurable location, with minimal scripting required".

4 Likes

I'm feeling the hype for 8.3.

2 Likes