Highlighted

CFFILE upload: get tmp filename???

LEGEND ,
Feb 15, 2018

Copy link to clipboard

Copied

Hello, all,

If I have a form that uploads a file, and the action page for that upload just does a CFDUMP of the form scope, one of the things I've noticed is:

form.uploadFile | {drive}:\ColdFusion\cfusion\runtime\work\Catalina\localhost\tmp\neotmp698498469158.tmp

This is the tmp directory where the web server uploads to for your CFFILE action="upload" to tell it where to be saved to.  Then, the .tmp file automatically deletes.

I am trying to devise a way to use CFFILE action="readbinary" directly from the tmp folder, without using action="upload" to cut down on disk I/O.

Is there a way to determine the tmp path and filename (other than CFDUMP) when the web server saves the file?  WITHOUT using action="upload".

V/r,

^ _ ^

I am gobsmacked.

As I was playing around with getTempDirectory(), it just flashed in my mind:  form is a struct.  The following code does precisely what I want to do, is WAY more simple than I thought I was going to need, and.. and.. smh

<cfswitch expression="#StructKeyExists(form,'fileField')#">

     <cfcase value="yes">

          <cffile action="readbinary" file="#StructFind(form,'fileField')#" variable="thisFile" />

          <cfdump var="#variables.thisFile#" />

     </cfcase>

</cfswitch>

This code displays a (truncated) binary code in string format.  Correction:  This code displays a binary code in string format, but the string is truncated.  Now I have the file object that I need to insert into an email and push to the mail server.  And it was so simple! 

V/r,

^ _ ^

Views

1.1K

Likes

Translate

Translate

Report

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

CFFILE upload: get tmp filename???

LEGEND ,
Feb 15, 2018

Copy link to clipboard

Copied

Hello, all,

If I have a form that uploads a file, and the action page for that upload just does a CFDUMP of the form scope, one of the things I've noticed is:

form.uploadFile | {drive}:\ColdFusion\cfusion\runtime\work\Catalina\localhost\tmp\neotmp698498469158.tmp

This is the tmp directory where the web server uploads to for your CFFILE action="upload" to tell it where to be saved to.  Then, the .tmp file automatically deletes.

I am trying to devise a way to use CFFILE action="readbinary" directly from the tmp folder, without using action="upload" to cut down on disk I/O.

Is there a way to determine the tmp path and filename (other than CFDUMP) when the web server saves the file?  WITHOUT using action="upload".

V/r,

^ _ ^

I am gobsmacked.

As I was playing around with getTempDirectory(), it just flashed in my mind:  form is a struct.  The following code does precisely what I want to do, is WAY more simple than I thought I was going to need, and.. and.. smh

<cfswitch expression="#StructKeyExists(form,'fileField')#">

     <cfcase value="yes">

          <cffile action="readbinary" file="#StructFind(form,'fileField')#" variable="thisFile" />

          <cfdump var="#variables.thisFile#" />

     </cfcase>

</cfswitch>

This code displays a (truncated) binary code in string format.  Correction:  This code displays a binary code in string format, but the string is truncated.  Now I have the file object that I need to insert into an email and push to the mail server.  And it was so simple! 

V/r,

^ _ ^

Views

1.1K

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 15, 2018 0
Adobe Community Professional ,
Feb 15, 2018

Copy link to clipboard

Copied

I don't know the answer to your question. But if both CF and the ultimate destination are on the same disk partition, I don't think you'll reduce disk I/O by doing what you're trying to do. And I would probably spend more time figuring out how to move CF's tmp directory to the other disk partition than to read directly from the tmp folder.

Dave Watts, CTO, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2018 0
LEGEND ,
Feb 15, 2018

Copy link to clipboard

Copied

Hi, Dave,

My point is that if you upload a file and use CFFILE action="upload" then the binary is pushed across the network, saved to the tmp folder (one write by web server), and CFFILE copies it to the destination (one read, a second write, by CF).  If I can use action="readbinary" from the tmp folder and skip that second write, it's worth it to me, even if the file is < 100k.  And some of these files might be more like anywhere from 1M to 2M (Excel files with multiple sheets each containing hundreds of rows of data, 12-24 columns across, depending.)

Moving the tmp folder to the same partition as CF might work in my personal dev environment at home, but the PTB controlling our staging and production environments certainly will not allow it, nor will our dev SA, here at work.  I could ask, but I'd just get a blank stare, I'm fairly certain.

V/r,

^ _ ^

PS:  Almost forgot.. there will be one more read by CF of the file to put it into a file object for processing.  So, two writes, two reads, one file.  Just seems like a lot of disk I/O for large files, and this application will be used world-wide by hundreds, if not thousands, of users.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2018 0
Adobe Community Professional ,
Feb 15, 2018

Copy link to clipboard

Copied

But the second read and write won't use any significant amount of I/O if the source and destination are on the same partition. The file won't literally be moved anywhere, it will just be relabeled by the filesystem with its new location. The tmp folder is nested within the CF folder already. The question is, is the ultimate destination of the file on the same partition as the tmp folder? If it's not, can you change one or the other so that they are? Why not change the UPLOAD attribute so that it points to somewhere on the same partition as CF and the tmp folder? I think that would be easier than trying to dissect the file upload process. I don't think IIS temp file space is used by default, the upload is just stored in memory until the CF connector grabs it and writes it to disk in its own tmp folder.

Dave Watts, CTO, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2018 0
LEGEND ,
Feb 15, 2018

Copy link to clipboard

Copied

Dave,

Some of your questions I am not at liberty to answer.  NDA, security clearance, all that jazz.  I can tell you we're using ColdFusion.

https://forums.adobe.com/people/Dave+Watts  wrote

The question is, is the ultimate destination of the file on the same partition as the tmp folder?

It is not.

https://forums.adobe.com/people/Dave+Watts  wrote

If it's not, can you change one or the other so that they are?

I answered this in my last post.  On my home DEV network, I am in complete control and can do that.  At work, the Powers That Be will NOT allow them to exist on the same partition for staging nor production, nor will our development SA allow it.  Out of my hands.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2018 0
Adobe Community Professional ,
Feb 15, 2018

Copy link to clipboard

Copied

Wolf, the simple answer to your first question is: use the CFML function, gettempdirectory().

I discuss this in the context of the whole question about how form posts of files and cffile upload processing really works (and how the file is put there regardless of that tag being there, and how all that tag does is just *move* the file, etc.), in a 2006 blog post here:

CFMythbusters: For a file to be uploaded to CF, the page needs a CFFILE Upload tag, right? Wrong!

With that out of the way, I understand your desire to find another way than to use the upload, but I've watched the back and forth with Dave. I'm (as usual) with him. First, even if you could do what you want, wouldn't your "Readbinary" of the file be "another bunch of disk io" (the read of it, to memory)? And then what would you be doing, with that file once in memory? Writing it somewhere? Wouldn't your write to that "new location" be another set of disk io? So the real question (setting aside your desires, challenges, considerations) would then seem to be, are you really saving anything?

Or might this be a case that in your need to be clandestine :-), you're not REALLY describing the actual situation? But instead you're using terms and concepts that you think would present a scenario where your need for what you request would seem "reasonable" to anyone looking? If that's the case, then if the first answer I offer does it for you, great. 🙂

/Charlie (server troubleshooter, carehart.org)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2018 1
Adobe Community Professional ,
Feb 15, 2018

Copy link to clipboard

Copied

Well, it looks like you can read the contents of the tmp directory instead of completing the processing of the upload, I guess! So give that a try and see if it reduces your overall time. I guess it depends on where the copy of the file you're reading is being stored, and what you're trying to do with it once you read it. I don't know whether the additional work you'll have to do to identify the tmp file in question, delete that file, etc will be worthwhile or not.

Dave Watts, CTO, Fig Leaf Software

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 15, 2018 0
LEGEND ,
Feb 16, 2018

Copy link to clipboard

Copied

Anything uploaded to the tmp directory is immediately deleted, automatically, after upload, delayed only by whatever code one writes to process the file.  There will be no additional work as far as deleting the file.  And Charlie's suggestion of getTempDirectory() just might work.  I'll try that and report back. 

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 16, 2018 0
LEGEND ,
Feb 16, 2018

Copy link to clipboard

Copied

Charlie, I'm facepalming myself because I never even thought of getTempDirectory() - it just wasn't on my radar.  I'll give that a shot.  I have a good feeling that it will work.  Thank you for the suggestion, and I will check your blog entry when I have a chance.

charlie@carehart.org  wrote

First, even if you could do what you want, wouldn't your "Readbinary" of the file be "another bunch of disk io" (the read of it, to memory)?

Unless I misunderstand the process, form pushes binary to web server which saves to tmp directory (one write).  From this point, if I use "readbinary", that's a read from the disk that stores the binary into a variable/file object (one read).  As far as deleting the file, which is automatic, there is only one minor thing that happens - the file isn't actually deleted, the filename is changed so that the first character of the filename becomes a question mark (?) so that it is invisible to the table of contents and can be overwritten by the OS at any time.  Using CFFILE action="upload", the file is written to tmp, read from tmp, written to destination, then read from destination for processing.  Two writes, two reads, on a system where the tmp folder is not on the same partition as the webroot.  Even with the faster disk drives, even SDD, the difference is marginal, yes.  But I'm that OCD about certain things.  And there is something else involved that I am not at liberty to discuss. 

charlie@carehart.org  wrote

And then what would you be doing, with that file once in memory? Writing it somewhere? Wouldn't your write to that "new location" be another set of disk io?

As of this writing, the file will be attached to an email and sent to an organization inbox.  The future, however, involves inserting the file into a database as part of a custom built processing application that will allow authorized users to browse and search the data.

charlie@carehart.org  wrote

Or might this be a case that in your need to be clandestine :-), you're not REALLY describing the actual situation? But instead you're using terms and concepts that you think would present a scenario where your need for what you request would seem "reasonable" to anyone looking?

I think clandestine could apply, yes.    When you work for the DoD, you can't always reveal all details.  So I have to get creative, sometimes, in order to express a concept or situation.

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 16, 2018 0
LEGEND ,
Feb 16, 2018

Copy link to clipboard

Copied

I am gobsmacked.

As I was playing around with getTempDirectory(), it just flashed in my mind:  form is a struct.  The following code does precisely what I want to do, is WAY more simple than I thought I was going to need, and.. and.. smh

<cfswitch expression="#StructKeyExists(form,'fileField')#">

     <cfcase value="yes">

          <cffile action="readbinary" file="#StructFind(form,'fileField')#" variable="thisFile" />

          <cfdump var="#variables.thisFile#" />

     </cfcase>

</cfswitch>

This code displays a (truncated) binary code in string format.  Correction:  This code displays a binary code in string format, but the string is truncated.  Now I have the file object that I need to insert into an email and push to the mail server.  And it was so simple! 

V/r,

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 16, 2018 0