NetTalk Central

Author Topic: Controlling uploaded file names  (Read 6637 times)

Mike Grigsby

  • Sr. Member
  • ****
  • Posts: 380
    • Yahoo Instant Messenger - onthedotsoftware
    • View Profile
    • MyHomeAssets! Software (among others)
Controlling uploaded file names
« on: December 10, 2007, 09:20:48 PM »
I'm having trouble wrapping my head around (and following the code backwards from the template) as to how to change the name of an uploaded file to be that of a date or customer number, for example. I wondered if someone has any suggestions or examples of how to do this.

For example, you might prompt a user to upload a file:

They enter: c:\somefolder\info.txt
It ends up in \web\uploads\info.txt

What I would like to do is have it end up something like: \web\uploads\[userID]_[date]

Anyone know how I can tweak the code to do this?
Mike Grigsby
Credify Systems
Central Oregon, USA

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Re: Controlling uploaded file names
« Reply #1 on: December 11, 2007, 11:40:53 AM »
Hello Mike,

thats quite easy to achieve.

Look at the NetWebHandler in the Embeds under RenameFile.
Code: [Select]
ReturnValue = PARENT.RenameFile(p_name,p_filename)
! [Priority 5001]
ReturnValue = PARENT.RenameFile(p_name, FORMAT(TODAY(), @D10-) & '_' & FORMAT(CLOCK(), @T04-) &'_'& p_filename)
! ReturnValue = PARENT.RenameFile(p_name, FORMAT(FIL:Date, @D10-) & '_' & FORMAT(FIL:Time, @T04-) &'_'& p_filename)
! End of "NetTalk Method Executable Code Section"
RETURN ReturnValue
Result in this sample is something like

  YYYY-MM-DD_HH-MM-SS_Filename.EXT

BTW: did you get the dynamical footer working?

bye
Wolfgang

Mike Grigsby

  • Sr. Member
  • ****
  • Posts: 380
    • Yahoo Instant Messenger - onthedotsoftware
    • View Profile
    • MyHomeAssets! Software (among others)
Re: Controlling uploaded file names
« Reply #2 on: December 13, 2007, 10:31:37 AM »
Sorry Wolfgang, I missed your question about dynamic footers. Footers are still an enigma to me. I can add all the headers I want, but I haven't figured out where to put footer code just yet. Thanks so much for your code example for the file upload stuff!
Mike Grigsby
Credify Systems
Central Oregon, USA

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Re: Controlling uploaded file names
« Reply #3 on: December 13, 2007, 02:08:57 PM »
The header / footer is usualy a NetWebSource. Add a NetWebBorder. In the HTML-Tab (you can define a condition here) you add a HTML-formed comment pointing to a f:(file)variable which points to a text-file:

<!-- Net:f:inc\myfooter.inc.txt -->

I have a folder called inc, where I store all txt that get included. Those files may comtain HTML-tags and may be modified at runtime, no recompile needed!

hth
Wolfgang

Mike Grigsby

  • Sr. Member
  • ****
  • Posts: 380
    • Yahoo Instant Messenger - onthedotsoftware
    • View Profile
    • MyHomeAssets! Software (among others)
Re: Controlling uploaded file names
« Reply #4 on: December 13, 2007, 11:05:34 PM »
Hi Wolfgang, thanks for you help! I wonder if you can help me understand how to pass a value to the renaming stuff. I was trying to use the system ID (e.g. fil:sysID) as the prefix to the file name.

I tried using a p_web.GetSessionValue... kind of deal, but it's not a web procedure, so that won't work.

After spending a lot of time on the issue, I can't think of a way to pass the sysID to the file renaming code. Have you encountered this before?
Mike Grigsby
Credify Systems
Central Oregon, USA

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Re: Controlling uploaded file names
« Reply #5 on: December 15, 2007, 10:36:59 AM »
Hello Mike,

try this:
In the Procedure Setup-Embed of the NetWebSource Procedure to upload the file:

Quote
p_web.SetSessionValue('IDstring', .... Put the ID here .... )

I assume that you have the ID at your hand at this Embed.... ;-)


In the RenameFile-Embed of the WebHandler

Quote
ReturnValue = PARENT.RenameFile(p_name, FORMAT(TODAY(), @D10-) & '_' & FORMAT(CLOCK(), @T04-) &'_'& PARENT.GetSessionValue('IDstring') &'_'&p_filename)
                                     

Perhaps this works the way you want.

Bye
Wolfgang

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Controlling uploaded file names
« Reply #6 on: December 17, 2007, 12:22:33 AM »
Hi Mike,

>> I tried using a p_web.GetSessionValue... kind of deal, but it's not a web procedure, so that won't work.

You're actually _inside_ the p_web object at that point. (Indeed anything you embed in webHandler is inside that object.) So instead of using P_WEB use SELF. For example;

ReturnValue = PARENT.RenameFile(p_name, FORMAT(TODAY(), @D10-) & '_' & FORMAT(CLOCK(), @T04-) &'_'& SELF.GetSessionValue('IDstring') &'_'&p_filename)

Cheers
Bruce