• 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
question about posting about downloading file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

question about posting about downloading file


  • Subject: question about posting about downloading file
  • From: "Leon zhao" <email@hidden>
  • Date: Mon, 27 Oct 2003 20:53:09 +0000

Hey everyone

I am trying to figuring out how to download files from the webobjects through hyperlinks in the page.
I found some valuable
postings about the topic. But there are several things that I remains not clear abuot the posting:


1. String theURLName = < object of your choice resolves the argument to
a hidden URL >;
what does < object of your choice resolves the argument to
a hidden URL >mean?
for example if I want to download /Users/leon/text from 128.163.112.16:8080 which is the web application what is the theURLNName should be like.


2. what is aFileName ?

Any posting is highly appreciated!

Leon
==================the posting about how to download file=================




Hi Marcus,

So you need to hide the URLs to unauthorized files.

Let's assume you have a WORepetition of WOHyperlinks to authorized
downloads, where the WORepetition's "item" binding is to the String
"aFilename".

1.  You can bind the WOHyperlink's action to an action method like
getDownloadFile, of the general form:

  public WOComponent getDownloadFile() {
      WOComponent dlStream = pageWithName( "DownloadStream" );
      dlStream.takeValueForKey( aFilename, "fileName" );
      dlStream.takeValueForKey( fileDataForName( aFileName ), "data" );

      return dlStream;
  }

2.  You'd need an auxiliary method fileDataForName( String someName ), which
in this example is set up to go in the .java source file for the WOComponent
containing the getDownloadFile() method.  Or, you might want to smarten up
the "DownloadStream" component to prep the download data internally when
given a new name.  That's probably better.  But anyway, the
fileDataForName() method would look something like this:

   public NSData fileDataForName( String aName ) {

      String theURLName = < object of your choice resolves the argument to
a hidden URL >;

      URL theURL;
      BufferedInputStream bis;

      NSData returnData;

      try {
          theURL = new URL( theURLName );
          bis = new BufferedInputStream( theURL.openStream() );
          byte[] data = new byte[ bis.available() ];
          int bytes_read = 0;
          while (bytes_read < data.length)
              bytes_read += bis.read( data, bytes_read, data.length -
bytes_read );
          bis.close();
          returnData = new NSData( bis.toByteArray() );

      } catch ( Exception e ) {
         // find some other way to get some returnData here :-)
      }

      return returnData;

  }

3.  Then, you'll need the "DownloadStream" WOComponent.  (Somebody on this
list gave me about 98% of this little beauty a few weeks ago.  I can't
remember who you were, but thanks again!)


********************** BEGIN DownloadStream.java

public class DownloadStream extends WOComponent {


// // You'll probably want to do keyvalue coding to set this next // ivar for various file types, like PDF. Currently, it's a // constant for me... // protected String contentType = "text/report";

  //
  //  Default filename
  //
  protected String fileName = "download.txt";

  protected NSData data = null;



  public void appendToResponse( WOResponse r, WOContext c ) {
      //
      //  Notice there is no call to super
      //
      r.setHeader( contentType, "Content-Type" );

      r.setHeader( "attachment; filename=\"" +
                   fileName + "\"", "Content-Disposition" );
      r.setContent( data );
  }


}

********************** END DownloadStream.java

4.   You'll need blank .wod and .html files for this component, unless you
redo it as a dynamic element.

HTH,

- dan

_________________________________________________________________
Fretting that your Hotmail account may expire because you forgot to sign in enough? Get Hotmail Extra Storage today! http://join.msn.com/?PAGE=features/es
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: WO522Developer.dmg
  • Next by Date: Re: WO522Developer.dmg
  • Previous by thread: Re: WO522Developer.dmg
  • Next by thread: WO-Component-Editor?
  • Index(es):
    • Date
    • Thread