Alpha Video Training
Results 1 to 9 of 9

Thread: File Upload feature pack and rename

  1. #1
    Member
    Real Name
    Dan Hooley
    Join Date
    Jan 2008
    Location
    Washington (State)
    Posts
    343

    Default File Upload feature pack and rename

    Is there a way to rename the file that is being uploaded using the File Upload feature pack? I am trying to upload pdf's and need to rename them based on several fields in the current row. Something like 'id + Last Name + First Name + date .pdf'. Are these options in the 'e' object and if so, how are they reference? Or is there a better option for uploading, storing and printing pdf's?
    - Dan Hooley


    - Custom Desktop or Web database development -

  2. #2
    "Certified" Alphaholic
    Real Name
    Frank Bicknell
    Join Date
    Feb 2010
    Location
    39.1915° N, 84.4348° W
    Posts
    2,467

    Default Re: File Upload feature pack and rename

    Yes. There are some examples in the action pack videos of how to do this in the AfterUpload event. Also when you generate a Function Prototype for Server-side Event for the AfterUpload Event there is a sample of code.

  3. #3
    "Certified" Alphaholic peteconway's Avatar
    Real Name
    Peter Conway
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    2,666

    Default Re: File Upload feature pack and rename

    The answer is in this thread.
    http://msgboard.alphasoftware.com/al...ghlight=upload
    Pete.
    Insanity: doing the same thing over and over again and expecting different results.
    Albert Einstein, (attributed)
    US (German-born) physicist (1879 - 1955)

  4. #4
    Member
    Real Name
    Dan Hooley
    Join Date
    Jan 2008
    Location
    Washington (State)
    Posts
    343

    Default Re: File Upload feature pack and rename

    The answer is in this thread.
    http://msgboard.alphasoftware.com/al...ghlight=upload
    Pete.
    That thread is about the Image Upload feature pack and is different than the File Upload. If you look at the Function Prototype's, you can see that the 'e' object is different.
    - Dan Hooley


    - Custom Desktop or Web database development -

  5. #5
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: File Upload feature pack and rename

    Dan, here is the code I came up with last night for this. One of the things that threw me is the e.primaryKeyArray returns the RECNO for DBF table.

    Code:
    'upload one file to existing record
    'rename the file and store in the table and folder under data folder
    'overwrite any existing file by same name
    'this is the old filename, we don't use it in the code -> e.fileArray[1].fileName
    
    dim arr as p
    arr = e.filearray
    
    fldr = filename_decode("[PathAlias.ADB_Path]\attachments" + chr(92))
    dir_create_recurse(fldr)
    
    dim tbl as p
    tbl = table.open("[PathAlias.ADB_Path]\mytable")
    tbl.fetch_goto(val(e.primaryKeyArray[1])) ' this is the RECNO since we are using DBF
    
    fext = file.filename_parse(e.fileArray[1].fileName,"E")
    dim newfilename as c = "newname_" + alltrim(tbl.id) + fext
    dim data as b
    data = e.fileArray[1].data
    file.from_blob(fldr + newfilename,data)
    
    tbl.change_begin()
    tbl.myupload = newfilename
    tbl.change_end()
    
    tbl.close()
    
    e.javascript  = "window.parent.{grid.object}.refresh();"
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  6. #6
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: File Upload feature pack and rename

    Here is an enhancement if you want to save the upload to an existing or new record. Plus a video: http://www.screencast.com/t/kJImfHsj

    Code:
    function saveFiles as v (e as p)
    
    'upload one file to existing or new record
    'rename the file, include the ID in the new name
    'save the new filename in the table
    'save the uploaded file in a subfolder under application data folder
    'overwrite any existing file by same name
    
    dim arr as p
    arr = e.filearray
    
    fldr = filename_decode("[PathAlias.ADB_Path]\attachments" + chr(92))
    dir_create_recurse(fldr)
    fext = file.filename_parse(e.fileArray[1].fileName,"E")
    
    dim data as b
    data = e.fileArray[1].data
    
    dim tbl as p
    tbl = table.open("[PathAlias.ADB_Path]\mytable")
    
    if val(e.rowNumber) > 0 ' is an existing record
    	tbl.fetch_goto(val(e.primaryKeyArray[1])) ' this is the RECNO since we are using DBF
    	newfilename = "newname_" + alltrim(tbl.id) + fext	
    	tbl.change_begin()
    	tbl.myupload = newfilename
    	tbl.change_end()
    else
    	tbl.enter_begin()
    	newfilename = "newname_" + alltrim(tbl.id) + fext	
    	tbl.myupload = newfilename
    	tbl.enter_end()
    end if
    
    file.from_blob(fldr + newfilename,data)
    
    tbl.close()
    
    e.javascript  = "window.parent.{grid.object}.refresh();"
    
    end function
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  7. #7
    Member
    Real Name
    Norman Mouton
    Join Date
    Aug 2010
    Posts
    103

    Default Re: File Upload feature pack and rename

    What will the code be for MYSQL?

    Thanks in advance

  8. #8
    Member
    Real Name
    Norman Mouton
    Join Date
    Aug 2010
    Posts
    103

    Default Re: File Upload feature pack and rename

    Steve

    The link to the video does not work.

  9. #9
    Member J.R. Noe's Avatar
    Real Name
    J.R. Noe
    Join Date
    Feb 2011
    Location
    Brandenburg, KY.
    Posts
    403

    Default Re: File Upload feature pack and rename

    I know this post started a long time ago, but I am still looking for something like this. Steve, I am using version 11 and your template, set up as multi-user and multiple agencies, so I need a way for users from many agencies to upload a file and ideally use their id or some unique identifier for the user in the file name.

Similar Threads

  1. File upload feature pack
    By J.R. Noe in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 03-09-2011, 06:31 PM
  2. Feature Pack - File Upload/download
    By omagarc in forum Application Server Version 10 - Web/Browser Applications
    Replies: 6
    Last Post: 09-16-2010, 11:53 AM
  3. Upload File Feature Pack Not Showing Upload Page
    By ogmcheck in forum Application Server Version 10 - Web/Browser Applications
    Replies: 4
    Last Post: 09-01-2010, 08:10 PM
  4. File Upload - New Feature Pack - NOT WORKING
    By jacsolutions in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 08-24-2010, 01:10 PM
  5. Image and file upload feature pack
    By Pat Bremkamp in forum Application Server Version 10 - Web/Browser Applications
    Replies: 3
    Last Post: 08-22-2010, 02:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •