Alpha Video Training
Results 1 to 7 of 7

Thread: File Upload and Updated Database Table

  1. #1
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    637

    Default File Upload and Updated Database Table

    I am doing a file upload and after it completes then updating a database table with the new URL for Amazon S3 bucket. In the file upload Javascript action, the On Upload Complete I have

    {dialog.object}.runAction('AJAX CALLBACK TO UPDATE DATABASE ID URL');

    In that action I have an AJAX CALLBACK Action Javascript that calls an XBasic Function updateIdVideoUr. With the XBasic Function, I want to update a database table with a URL for Amazon S3 and at the end of the URL put the filename of the file uploaded. Here is the XBasic Function below but it isnt updating the database:

    function updateIdVideoUrl as v (e as p)

    dim globalcn as sql::connection
    dim sql as c
    dim args as sql::arguments
    dim flag as l



    flag = globalcn.open("::name::petvv")
    args.set("currentpetid", e.dataSubmitted.PETID)


    flag = globalcn.execute("UPDATE pvv_pet_videos SET URL = https://s3.amazonaws.com/pvvidvideos/e.name where PETID = :CURRENTPETID",args)

    end function

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,572

    Default Re: File Upload and Updated Database Table

    Have a look at your post... try to see if with a fresh perspective. You must see how your update statement is badly formatted. There are 2 errors in your statement.

    You're assigning a string to URL... where's the STRING?
    You're utilizing an e. variable... how is that being EVALUATED?

    Using the debugger would help so much. What is the error message you're getting?

  3. #3
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    637

    Default Re: File Upload and Updated Database Table

    What is the best way to debug the UX? The UX I am working with is embedded and when I try to do a working preview it wants a value that is passed from the parent UX and wont run.

    As far as the sql statement, I am trying to add the string https://s3.amazonaws.com/pvvidvideos and then add e.name at the end of it. The string https://s3.amazonaws.com/pvvidvideos isn't sitting anywhere I am just trying to add it in the sql update.

    As far as e.name variable, in the After Complete Javascript Action, it saids that e.name is returned which holds the file name of the uploaded file. So I am trying to add that at the end of the sql update.

    Can you give me anymore guidance?

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,572

    Default Re: File Upload and Updated Database Table

    Where is your URL string? How is e.name being evaluated? What would a valid SQL statement look like? Work through the problem.

    e.name cannot be evaluated inside a string the way you've written it.
    The URL, as you've used it, is not a string you can assign to a field.

    A valid SQL Update statement would be...
    UPDATE pvv_pet_videos SET URL ='https://s3.amazonaws.com/pvvidvideos/myvideo.mp4' where PETID = 1

    URL is being assigned a string.

    Now evaluate e.name... OUTSIDE the string...

    UPDATE pvv_pet_videos SET URL ='https://s3.amazonaws.com/pvvidvideos/'" + e.name

    Now build the variables you need...

    dim vidName as c
    vidName = "https://s3.amazonaws.com/pvvidvideos/" + e.name

    sql = "UPDATE pvv_pet_videos SET URL = '" + vidName + "' where PETID = :CURRENTPETID"
    flag = globalcn.execute(sql,args)

    Build a test UX... put in a debug(1) statement... call the XBasic function. Run it in LivePreview... step through each line of the code... see how each variable is being set.

  5. #5
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    637

    Default Re: File Upload and Updated Database Table

    Thanks, I am getting better at this, see exactly what you are saying. However, it is complaining that e.name is not found. In the On Upload Complete of File Upload it saids that e.name can be accessed. Do I have to declare e.name in the XBasic function and pass it someway to my XBasic Function? I thought it was just returned in the File Upload- On Upload Complete and could use it by e.name....

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,572

    Default Re: File Upload and Updated Database Table

    The e.name you're using is available, in that form, only in that Javascript, Client-side, code. It's not available server-side, in XBaisc, in that form.

    Instead of using runAction to call an Action... to call a callback... just simply call the callback. Using runAction is, quite often, a waste of time and an extra step. Not always... but often.

    Your Javascript On Upload Complete code could be...

    Code:
    {dialog.object}.ajaxCallback('','','updateIdVideoUr','','_videoName='+e.name);
    This is an Ajax Callback passing data into the XBasic function.

    Your original e.name value is being passed in to the 'e' object of the XBasic function... into a property named '_videoName'

    In your XBasic function, you'd get the video name...

    Code:
    dim vidName as c
    vidName = e._videoName
    Last edited by Davidk; 12-15-2017 at 06:53 PM.

  7. #7
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    637

    Default Re: File Upload and Updated Database Table

    It worked! Thanks! One thing I noticed when I uploaded the same file name for two different users it just kept one file on Amazon S3 and updated the same file name for the two different database fields. Is there anyway it can automatically rename a file if another file had already been uploaded with the same name? For example one file already uploaded named Test, then another one named Test uploaded, can it automatically change to Test1 or something?

Similar Threads

  1. File Upload - Upload a file to a server on internal network
    By swest in forum Application Server Version 11 - Web/Browser Applications
    Replies: 12
    Last Post: 08-28-2013, 10:52 AM
  2. File Upload/Download - Manually insert uploaded file into the database....
    By dionmccormick in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 07-16-2013, 10:49 AM
  3. How to get updated database table value in Xbasic when we use window.location.replace
    By satyanarayana in forum Application Server Version 11 - Web/Browser Applications
    Replies: 1
    Last Post: 06-29-2012, 09:27 AM
  4. Can’t seem to insert uploaded files into SQL table using feature pack file upload UD
    By Maroine81 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 08-31-2011, 03:57 AM
  5. Problem upload file feature pack - Can't select table fields
    By lyleelkins in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 07-14-2011, 12:05 AM

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
  •