Skip to main content
10-Marble
May 20, 2024 9:28 PM UTC
Solved

File Upload Widget File Name(s)

I am using the File Upload Widget and I would like to control the name of the file.

The user file name won't match what I want/need the filename to be in the repository.

Is there a way to change the name of the user selected file before (or after) uploading the file to the repository?

 

Background:

I'm using Thingworx 9.3.5-b1258

The file they are uploading is tied to a unique entity name from a database.

I want to use the unique name for the file in the repository for retrieval when the database record is selected. The file name the user has most likely will not match the name in the database.

LynnMAnswer
10-Marble
May 21, 2024 10:35 PM UTC

I added a property UserFilename and two services to my FileRepository.

SaveUserFileName updates the UserFilename property if the filename isn't null

GetUserFileName returns the UserFilename property

 

3 replies

16-Pearl
May 21, 2024 3:04 PM UTC

Hi @LynnM ,

 

You use the Repository entity service called  RenameFile to rename the file based on your required by any of unqiue combination. You can also execute this service once the user upload the file through the FileUpload widget. It will help to maintain the file names as unique.

Things["SystemRepository"].RenameFile({
	path: p_PathName /* STRING */,
	name: p_NewFileName /* STRING */,
	overwrite: true /* BOOLEAN {"defaultValue":false} */
});

 

Thanks & Regards,

Arun C

 

Translate
LynnM10-MarbleAuthor
10-Marble
May 21, 2024 8:38 PM UTC

Rename looks straight-forward and shouldn't be a problem IF the filename selected by the user can be captured.

I bound the ptcsfileupload  "FileNames" property to a label so I could capture the name of the uploaded file but as soon as the "Upload" button is clicked, the FileNames property is nulled out.

How can I capture and keep the value of the FileNames property so I know what user filename to rename as what I want it to be?

Translate
LynnM10-MarbleAuthorAnswer
10-Marble
May 21, 2024 10:35 PM UTC

I added a property UserFilename and two services to my FileRepository.

SaveUserFileName updates the UserFilename property if the filename isn't null

GetUserFileName returns the UserFilename property

 

Translate