• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Download of text file created on the fly, repeat problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Download of text file created on the fly, repeat problem


  • Subject: Re: Download of text file created on the fly, repeat problem
  • From: Chuck Hill <email@hidden>
  • Date: Thu, 21 Apr 2005 13:05:52 -0700

WO takes a shortcut when a URL is requested again. It skips over the takeValues and invokeAction phases and goes directly to appendToResponse. You could just set a flag in invokeAction and check it in appendToResponse. If it is clear in appendToResponse then the page is being reloaded. The problem is that you don't know if the page is being reloaded from the download link or some other way and you will trigger the download when you don't want it.

A better idea is to initiate the download in a direct action but then you have the problem of knowing what to download from the direct action. Assuming that security is a concern, you would need to do something like pass a key in the download direct action URL and use this to look up the content from some storage in the session.

The best way to handle this that I can think of off hand is to make your own hyperlink component that adds a known component to the URL (e.g. .downloadnow). Then rather than setting a flag in the action method, you check the URL for this component.


Chuck


On Apr 21, 2005, at 6:36 AM, Jon Kleiser wrote:

I have a page with a WOHyperlink that lets the user generate and download a text file, but my implementation has a weakness: The download method does not get called every second time the user clicks this link. It's probably got to do with "path ID" mismatch, but I don't know how to fix it. I'll describe my implementation ...

The download method just sets a flag, like this:

  public WOComponent download() {
    isDownloading = true;
    return this;
  }

The appendToResponse method delivers the text file and resets the flag:

public void appendToResponse(WOResponse resp, WOContext ctxt) {
if (isDownloading) {
String text = "test test test";
resp.setHeader("application/octet-stream", "content-type");
resp.setHeader("attachment; filename=\"test.txt\"", "content-disposition");
resp.setContent(text);
resp.setHeader(Integer.toString(text.length()), "content-length");
resp.disableClientCaching();
resp.removeHeadersForKey("Cache-Control");
resp.removeHeadersForKey("pragma");
isDownloading = false;
} else {
super.appendToResponse(resp, ctxt);
}
}


As long as the user don't try to download more than once, this works, but if he/she tries another download immediately after the first, nothing happens. (The download method doesn't get called the second time, but appendToResponse gets called.) I'll appreciate any ideas on how to fix it.

Jon Kleiser
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
village.net


This email sent to email@hidden

--
Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects




_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Download of text file created on the fly, repeat problem (From: Jon Kleiser <email@hidden>)

  • Prev by Date: Re: recovering from a validation exception
  • Next by Date: Re: WOHyperlink secure binding and insecure domain
  • Previous by thread: Download of text file created on the fly, repeat problem
  • Next by thread: D2W and CooperatingEditingContext: Can anybody use together?
  • Index(es):
    • Date
    • Thread