Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFFile action="uploadall" question

Guest
Apr 04, 2011 Apr 04, 2011

I am doing a cffile uploadall process and I want to return a list/array of filenames uploaded.  It doesn't seem like it should be too hard - should it?

Thanks.

2.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 04, 2011 Apr 04, 2011

Take a look at the CF documentation.  It states: After a file upload is completed, this tag creates an array of structures specified by the result parameter. Each structure in the array contains upload result information for one file. For information on the result structure contents, see cffile action = "upload".

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 04, 2011 Apr 04, 2011

Here's my code:

Upload page -

<cffileupload
hideuploadbutton="no"
progressbar= "no"
stoponerror="yes"
title="Upload Closeout Pictures"
url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(form.type)#"
wmode="transparent"
maxfileselect=6 />

<cfif isDefined("myImage.serverfile")>
      wow
<cfelse>
      hey
</cfif>

Processing page -

<cffile
action="uploadall"
destination="#path#"
nameconflict="overwrite"
result="myImage" />

I get nothing in the myImage variable.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 04, 2011 Apr 04, 2011

Are any errors logged? It sounds like the file upload process is failing. You might try setting stoponerror="false" and use onError to gather information about the upload process from the cffileupload tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 04, 2011 Apr 04, 2011

The upload is working fine - the files are going exactly where they should go.  What I want to do is, after the upload, update a single record in a database with between 1 - 6 image names that were uploaded.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 04, 2011 Apr 04, 2011

If the upload succeds you should have something your myImage variable. Try something like this in process.cfm to see what is captured in the result variable:

<cffile action="uploadall" destination="#path#" nameconflict="overwrite" result="myImage">

<cfif IsDefined("myImage")>

    <cflog text="Upload complete" type="information">

     <cfif IsArray(myImage)>

           <cflog text="#ArrayLen(myImage)# files uploaded" type="information">

     </cfif>

</cfif>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 04, 2011 Apr 04, 2011

What do you mean when you write "I get nothing in the myImage variable."  Is an exception thrown, is the array empty, etc?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 04, 2011 Apr 04, 2011

I do the isDefined( ) in a cfif and it does not validate.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 04, 2011 Apr 04, 2011

Not sure if I'm reading this right - but what page is the <cfif IsDefined("myImage")> declared?  In the "Upload" page or the "Processing" page?  If it's in the "Upload" page (the one containing <cffileupload - from the code you have supplied) then it will always evaluate to false as "myImage" was declared and teminated in the "process.cfm" page.  You would need to do that check within the process.cfm page and update your database within that page too.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 05, 2011 Apr 05, 2011

I certainly don't claim to know but when putting the logic in the processing page, I never got anywhere because of the flash object. I saw an example somewhere of someone that put the logic into the upload page so I tried it. I can get the processing page to return data to upload page - just not the variable I'm trying to evaluate.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 05, 2011 Apr 05, 2011

Bear in mind that the Flash based file upload operates asynchronously rather than on a syncronous form post and response used with a form based file upload. I agree with the other poster that your database update logic should be handled on the process.cfm page.

If you must have the client handle data processing you can try the onError, onComplete, and onUploadComplete features of cffileupload, but I would recommend against having the client be responsible for this kind of logic.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 05, 2011 Apr 05, 2011

I'm OK with that. Can anyone give me an example or point out what needs to be

changed in my code posted earlier?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 05, 2011 Apr 05, 2011

On upload.cfm:

<cffileupload
hideuploadbutton="no"
progressbar= "no"
stoponerror="yes"
title="Upload Closeout Pictures"
url="process.cfm"
wmode="transparent"
maxfileselect=6>

On process.cfm

<cfset targetPath="X:\a-file-storage-directory">

<cffile action="uploadall" destination="#targetPath#" nameconflict="overwrite" result="uploadedFiles">

<!--- iterate over uploadedFiles result array and perform an insert for each record --->
<cfif IsDefined("uploadedFiles") and IsArray(uploadedFiles) and ArrayLen(uploadedFiles) gt 0>

    <cfloop from="1" to="#ArrayLen(uploadedFiles)#" index="idx">
   
        <cfquery name="insertFileRecord">
           
            INSERT INTO FileHistory ( DirectoryName, FileName  )
            VALUES (
                <cfqueryparam value="#uploadedFiles[idx].serverDirectory#" cfsqltype="cf_sql_varchar"> 
                ,<cfqueryparam value="#uploadedFiles[idx].serverFile#" cfsqltype="cf_sql_varchar">
                );

        </cfquery>

   
    </cfloop>

</cfif>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 06, 2011 Apr 06, 2011

I used your code and received a 500 status error in the flash object. I believe it is because I have to pass variables to the processing page for the query.

On the upload page:

<cffileupload

hideuploadbutton="no"

progressbar= "no"

stoponerror="yes"

title="Upload Closeout Pictures"

url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(type)#"

wmode="transparent"

maxfileselect=6 /

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 06, 2011 Apr 06, 2011

Did you check the ColdFusion log to see what errors, if any, were logged?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 06, 2011 Apr 06, 2011

Yes, and I was able to fix the error. Now my problem is... it only updates with the last of the image names.

My table layout is

Pro_num, type, issue, pic1, pic2, pic3, pic4, pic5, pic6

Even though I uploaded 2 images, it updated pic1 with the second image name. I'm not sure if that makes sense.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 06, 2011 Apr 06, 2011

Please post your code.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2011 Apr 07, 2011

</cfif

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2011 Apr 07, 2011

Your code was truncated.  Please also post both the upload.cfm and process.cfm pages.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2011 Apr 07, 2011

Upload.cfm

</cfif

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2011 Apr 07, 2011

Your code continues to be truncated. If you are using email to reply please consider using the forum's web page instead. I have found that code is frequently mangled when posting to the forum by email.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2011 Apr 07, 2011

Upload.cfm

                <cffileupload

                hideuploadbutton="no"

                progressbar= "no"

                stoponerror="yes"

                title="Upload Closeout Pictures"

                url="process.cfm?pro_num=#pro_num#&type=#urlencodedformat(type)#"

                wmode="transparent"

                maxfileselect=6 />

Process.cfm

                <cfset path = #file_path# & "\" & #url.pro_num# >

                <cffile

                action="uploadall"

                destination="#path#"

                nameconflict="overwrite"

                result="uploadedFiles" />

                <!--- iterate over uploadedFiles result array and perform an insert for each record --->

                <cfif IsDefined("uploadedFiles") and IsArray(uploadedFiles) and ArrayLen(uploadedFiles) gt 0>

                <cfloop from="1" to="#ArrayLen(uploadedFiles)#" index="idx">

                                <cfset name = "pic" & idx>

                                <cfquery name="insertFileRecord" datasource="#application.dsn#">

                                                update closeout set #name# = '#uploadedFiles[idx].serverfile#'

                                               where pro_num = '#url.pro_num#' and type = '#url.type#'

                                </cfquery>

                </cfloop>

                </cfif>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2011 Apr 07, 2011

Since uploadall acts asynchronously a separate call to process.cfm might be made for each file uploaded. This would result in the name variable being equal to "pic1" for every file uploaded.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 07, 2011 Apr 07, 2011

I changed my database design to account for this "feature".  It sucks a little but it's working now.

Thanks for your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 07, 2011 Apr 07, 2011
LATEST

Perhaps a UI with six file input controls labeled pic 1-6 would be better suited to your site. That would allow you to contol which file corresponds to pics 1-6.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources