Coldfusion create unique file name




















Failure to provide a unique name will precipitate the following ColdFusion error:. Attribute validation error for the cfthread tag. Thread with name XYZ could not be created. Thread names must be unique within a page. As I've started to use CFThread inside of ColdFusion components , I developed a habit of generating these unique thread names using a combination of the parent method's name and a unique index.

And, in order to generate this unique index, I've been relying on Java's AtomicInteger. The AtomicInteger is great because it provides a fast way to increment values in a thread-safe manner without having to rely on relatively slow named-locking. In order to keep things as simple as possible, I usually factor out the thread-name generation into its own private method. To see what I mean, take a look at this sample ColdFusion component:. And, each thread name is tied to both the name of the ColdFusion component and to the name of the method that is spawning the thread.

I have found that this association makes the error logs much easier to read! It has a very simple method for generating a thread name. Legal Notices Online Privacy Policy. Description Writes a text file on the server, based on dynamic content. See also cfdirectory History See the History section of the main cffile tag page. If the user submitted a form with the following:.

ColdFusion supports using cffile to write an image, for example:. Sign in to your account. It isn't that much code or overhead and it's safer. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Can file names be changed on uploading with cffile? Ask Question. Asked 8 years, 10 months ago.

Active 4 years, 5 months ago. Ah, I get exactly what you're saying now. The way to get around that that pops into my mind would be to extend the primary Application.

Of course, then you can something like:. Sean Corfield presented a nice solution for that problem a little while back:. It took me like 8 times reading that to finally get quite what he was saying not his fault in any way , so if have any questions, please feel free to ask.

If you don't want to go the extend route, I am not sure there is going to be another elegant solution. I have a Stack Overflow question about extending Application. In the admin folder, I need to extend the ApplicationProxy that is one folder up, not the ApplicationProxy that is in the root.

One possible solution is to reverse the logic: have the top level Application. Another possible solution is to use a lot of cfincludes inside both Application. Yeah, extending the Application object is a bit more complicated than extending any other object because you cannot have per-application mappings.

Definitely makes things a bit more interesting. I'll give it a shot just for the sake of experimenting, but now i have to ask, is the small trouble to keep things set up with the empty 'proxy' file worth the small benefit of being able to auto-generate the application name. It all comes down to what you're able to maintain.

I ended up doing the auto-naming because I kept forgetting to create unique app names a by-product of copy-n-paste application creation. If you are fine with it, there's nothing particularly beneficial about using this approach. I've run into a different issue with this Application stuff, and I don't think the hash is going to fix it. Then, they're all signed on with the same name, and if one signs off they all get signed off. I'm thinking for best results we need to stuff a cookie with a guid or other variable and look for that on the machine that's running the system.

The problem I see, though, is when someone closes the browser and re-opens it, the cookie still exists if they did not sign off run the delete code. Here is another question about dynamic application name. How can we run a query first and get an id from a table and set the application name adding a string and this id?

If this is not possible, can we change the application. Light Dark. By using the current template path, we can ensure that our application name completely unique across the entire server. By using the hash function, we make the name more friendly.

That is an interesting way of doing it. I havnt tried that before. John, It's an approach that I happen to love! I have been bit by duplicate application names a couple of times. You could do the same in your hash. Ben Nice reminder. I would recommend adding cgi. Michael Feb 9, at PM 14 Comments. Hi Ben, If we do this, does it not cause more of a performance hit on the application because it doesn't already have the name cached somewhere?



0コメント

  • 1000 / 1000