Skip to main content
Gene_Godsey
Inspiring
April 29, 2011
Question

passing data using cffileupload

  • April 29, 2011
  • 5 replies
  • 9977 views

I am fully aware that this is a tag adobe created using a flash interface.

I also know that it does Not need to be nested inside of a torm tag. I need to capture the

File name and the path it took to be uploaded to the server so I can insert that into a database for search functionality.

Thoughts?

    This topic has been closed for replies.

    5 replies

    DaytonJack72
    Participant
    May 28, 2014

    If anyone is still interested in this post, I have it working and it is easy as pie.

    1) make sure you append ?#urlEncodedFormat(session.urltoken)# and any other variables to the page name in the URL attribute of the tag.  If you don't pass the url token it won't work because the AJAX used to upload the files is done behind the scenes.

    2) make sure you have NO HTML COMMENTS in your application.cfc or cfm files. These will murder the JSON returned and you will get the red error in the download box.  If you have any include files in your application scope you need to check them too.  I include a file of UDF's and that is where the HTML comments were hiding.  Rules of thumb, don't use HTML comments anymore at all.  Keep in mind that ANY visible content in your application scope will have the same effect.

    3) If you are still having issues, use Firefox or the Charles Proxy app to see what is being returned.  You can also use CFLOG to write the error info into a text file to be examined.

    I have this working on CF9, CF10, and 11 and every time it was HTML comments in there somewhere.

    Participant
    May 24, 2012

    actually, Talofer99 couldnt have spelled it out any simpler.

    But if you need a FULLL example of how to grab the name, extension and path and insert it into the DB... then here you go:

    <cffile action="uploadall"

    destination="/full/path/name"

    nameconflict="makeunique"

    result="uploadedfile"

    accept="image/*"

    >

    <CFSET fullimagename = "#uploadedfile.serverfilename#.#uploadedfile.serverfileext#">

    <CFSET fullpath = "#uploadedfile.serverDirectory#">

    <cfquery name="gallery_query" datasource="#Application.DSN#" username="#Application.Username#" password="#Application.Password#">

    INSERT INTO images (image_path,

    image_name)

    VALUES('#fullpath#',

    '#fullimagename#')

    </cfquery>

    You could prob do a better job at setting the name, perhaps with a date-time-id.jpg naming scheme to avoid wierd file names.

    You cant get any more straight forward than that.

    talofer99
    Inspiring
    May 25, 2012

    djeddieflux - I appricate what you wrote, to be hunst his response made me NOT want to helpeople any more, the above post was my last in any forum.

    
    talofer99
    Inspiring
    May 3, 2011

    ok... You are missing the BASIC of this TAG ...

    IT DOSN'T WORK as CFFORM does:

    You don't SUBMIT the uploaded files, they get submited in the BACKGROUND (for lack of any other wya to descirbe this).

    So once the FLASH is loaded and u press upload now, the page DOSN'T get SUBMITED, what ever yo uhave in the CFFORM Tha twraps the Tag is IGNORED !!

    Basicly the Flash is uplading the files to the server via http request in the background (did u actually tryed it ? di u see how it works ?)

    So ....

    lets say u did the follwing (which is almust all the u need or can actually place on the UPLAODING PAGE):

    <cffileupload
        url = "Save.cfm"/>

    The Save.cfm will look like this :

    <cffile 
        action = "uploadAll"
        destination = "full pathname"
        accept = "list of MIME types"
        attributes = "file attribute or list"
        mode = "permission"
        nameConflict = "behavior"
        result = "result name">

    THIS PAGE IS CALLED ONCE FOR EACH FILE THAT IS UPLOADED ....

    so if u choose 4 files .. the flash will submit tem ONE AT A TIME to the UPLOAD.cfm File ....

    And the acttion there will be almost teh same as if you had a reguler FORM FILE FIELD with one file ...

    IF yo udon;t spcify a result = "resultname" the result structure is CFFILE ....

    so if u dump the #cffile# you wil lge the name of the file uploaded and all the rest of the info. (IF itrs still not clear look at the CF reference for cffile uplaod)

    BUT sayign all this ... YOU DO NOT SE The result of the SAVE.cfm PAGE .. again because this happesn in the background ...

    If now things are STILL not clear ... I think maybe I'm nto the one to explain it ... and you migth consider takeing a course

    HAve fun

    Gene_Godsey
    Inspiring
    May 3, 2011

    OK,

    This is uploading great.

    /*-----------------------------------------------------*/

    <cffileupload 
        url="index_action.cfm?#urlEncodedFormat(session.urlToken)#"
        progressbar="true"
        name="myupload"
        width=400
        height=300
        title = "UPLOAD MULTIPLE FILES TO PRIVATE FOLDER"
        maxuploadsize="200"
        extensionfilter="*.jpg, *.png, *.flv, *.txt, *.doc, *.docx, *.xls, *.xlsx *.pdf"
        BGCOLOR="##0078AE"
    oncomplete="?"
        MAXFILESELECT="10" />

    /*---------------------------------------------------

    */

    <cffile action="uploadall"
      destination="#expandPath('uploads')#"
      nameconflict="overwrite"
      result="myVar" />

      <cfdump var="#myVar#">

    /*-----------------------------------------------------*/


    I guess now what I need to find is a reply back with the oncomplete attribute to get me the file names.

    BTW -  there is no reason to get angry about my lack of understanding here. I assure you I do not need a class.

    Thanks in advance for your assistance with this issue.

    talofer99
    Inspiring
    May 3, 2011

    No one is getting upset

    I just stated that if my last explantion is not enough to shad light on the subjectm I might not be the right person to anwer your Q' .. thats all ..

    and I suggested to you CONSIDER takeing some form os a study group/class/course ... thats all ... only a logic suggestion ... and I'm sorry if it made u think I think you NEES a course

    And read the CFFILEUPLOADER part in the manual and you will find this :

    onComplete

    Optional

    The JavaScript function to run when a file has finished uploading.

    By default, ColdFusion passes a JavaScript object as a parameter to this function with the following properties:
    • STATUS - numeric value that is based on the HTTP status code

    • MESSAGE - Passed or Failed

    • FILENAME - Name of the file selected for upload

    You can also pass the JavaScript object by creating a struct with parameters "status" and "message" and call serializeJSON() on the JavaScript object.

    talofer99
    Inspiring
    May 2, 2011

    When you say "Fail" what do you mean ?

    I had problems with it the first time I tryed it.

    What I did for debuging is to place a CFDUMP of the FORM inside a CFMAIL that was sent to me ...

    this way I was sure that the form is working.

    then I manged to get he files uplaoded ...

    and if u get the file uploaded there is no problem to store the info on that page, as long as u pas the info for it.

    for example if the file that is uploaded need to be saved for product ID#, pass that in the URL and u can do the database part on the fileuplaoding page.

    If you post the code yo udo have it might be easier to help you out.

    Gene_Godsey
    Inspiring
    May 2, 2011

    All of the code I have so far is nothing more than code examples from Ben Nadel or Ray Camden.

    Nothing new there.

    I need to know how to do cffileupload post-processing so I can process the file names into a database for datasearches and lookups to download them for the user or consumer of the uploaded files.

    Gene_Godsey
    Inspiring
    May 2, 2011

    I am still scouring the web for some kind of solution.

    talofer99
    Inspiring
    April 30, 2011

    when using cffileupload (http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec18238-7fd0.html) - which is the tag that creates the file uplaoder, have this attribute : URL

    Basicly the file are SUBMITED/UPLOADED one at a time to that page (the one specified in the url)

    so this page proccess the saveing of the uploaded image and you can use it to save things into a database.

    not that if you use session in your application, add this :?#urlEncodedFormat(session.urltoken)# ? to your url in order to keep the session in the proccessing page.

    here is the proccessing page tag

    http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7388.html

    hope this helps out

    Gene_Godsey
    Inspiring
    May 2, 2011

    I tried that and it failed in the processing as well

    as the flash uploader turned red. I need to find a way to successfully

    upload the files and somehow track the file(s)

    names so I can  insert them into a database for them to be searched and downloaded.

    Gene_Godsey
    Inspiring
    May 2, 2011

    I will assume that I will need a block of JavaScript for the oncomplete attribute.

    I have ssen a few examples but that is where this is seeming to head to.