Dynamically Creating Folder

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
rmullis
Experienced User
Posts: 100
Joined: Tue Feb 21, 2012 1:24 pm
First Name: Robert
Last Name: Mullis
Company Name: WRC
State / Province: Georgia
Country: United States
Contact:

Dynamically Creating Folder

Post by rmullis »

I would like to dynamically create a folder in /profoundui/userdata/custom based on the order number assigned in my program. I have looked at the online documentation to see if there is a PUI API that would allow me to do this, but I didn't see anything. Is there an API that would allow me to do this or is there any javascript that might help? I am just beginning to learn javascript, so go easy on me.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Dynamically Creating Folder

Post by Scott Klement »

Hiya Robert,

The profoundui/userdata/custom folder is intended for external JavaScript routines that you'd like to make available to your PUI applications. Any JavaScript code that's placed in this folder (or any subfolders beneath it) will be automatically loaded into your browser the next time you start a new PUI session.

I'm curious as to why you'd want to write data there, dynamically?

If you do want to create directories or write data to files (or another folder, for that matter) dynamically, you'd need to do that from the RPG side. This can be done using the IFS APIs (my personal preference) or using tools like the CPYTOSTMF command.

If you explain more about what your objective is, there may be an easier way.

Let me know if this helps, or if I can provide more information!
rmullis
Experienced User
Posts: 100
Joined: Tue Feb 21, 2012 1:24 pm
First Name: Robert
Last Name: Mullis
Company Name: WRC
State / Province: Georgia
Country: United States
Contact:

Re: Dynamically Creating Folder

Post by rmullis »

I want the user to be able to upload docs, pdfs, etc. related to a specific order. I want to store those files in a folder named the same as the order # and allow the user to display those files by clicking on a link when in the specfic order. I need to dynamically create this folder when a new order is created and, of course, delete the folder if the order is deleted.

Maybe creating the order's folder in /profoundui/userdata is better than /profoundui/userdata/custom.
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Dynamically Creating Folder

Post by Scott Klement »

Here's what I'm thinking:

1) Display a screen that asks for the order number. (You'll need this on the RPG side before displaying the upload widget.) Maybe you already have this.

2) RPG program calculates the upload directory from the order number, and puts it in a field.

3) field from #2 is bound to the "Upload Directory" on a File Upload widget.

4) File Upload widget takes care of uploading the files to the IFS.

In order to use the file upload, you need to define an "exit program" on the server. This is really simple to write, just a simple RPG.. It's explained here:
http://www.profoundlogic.com/docs/display/PUI/Security

That exit program can create the directory if it doesn't exist (this would be just extra code in the exit program). Or it could be done in step #2 by your RPG program. Either way would work. (Though, I like the exit program idea, in case the user hits the "cancel" button and doesn't upload anything The exit progam isn't run until the file is uploaded, so it won't be run if the user cancels)

Creating the directory can be done with the CRTDIR CL command, or with the mkdir() IFS API. I can provide an example if that's useful to you.

One more thing: If you upload to the /www/YOUR-PUI-INSTANCE/htdocs/profoundui/userdata directory, you should be aware that this directory is addressable by a direct URL, such as http://YOUR-SYSTEM:8080/profoundui/something.something

This may be a security issue, because users can bypass your application to view what's in those directories (if they know the URL). So it might be prudent to store in a different IFS directory, such as /your-app-name/data or something, outside of the /www part of the IFS.

The trouble with that is you wouldn't be able to get at the data once you put it there (at least, not via HTTP). So it's secure, but then when you need it, you can't get it. The workaround would be to write a program that downloads the data, but imposes security checks...

I know I'm throwing a lot of stuff out at you, and not going into much depth on it... please let me know if I can help further.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests