Re: Download file..
Re: Download file..
- Subject: Re: Download file..
- From: Robert Walker <email@hidden>
- Date: Thu, 25 Mar 2004 01:19:44 -0500
James,
I have a class that works quite nicely for me. The class file is named
FileDownloader.java and you can get it here:
http://homepage.mac.com/robertwalker1
Use the following action method for your download link or button:
public WOComponent downloadFile() {
FileDownloader fd = (FileDownloader)pageWithName("FileDownloader");
//Get the bytes from the file you want to download and pass them in
fd.setData(new NSData("This is a test download!".getBytes()));
//Set the mime type (i.e. "application/pdf" or "text/html")
fd.setMimeType("application/octet-stream");
//Set the file name
fd.setFileName("myFile.txt");
return fd;
}
On Mar 25, 2004, at 12:18 AM, James Cicenia wrote:
> Hello -
>
> I am confused where to put this appendToResponse. It can't be on my
> listing page as the appendToResponse will always be triggered.
> There will be a list of documents and that WOComponent will create the
> list, bind the item, etc.. so, where do I put the appendToResponse?
>
> -James
>
> On Mar 24, 2004, at 12:56 PM, steve stout wrote:
>
>> You'll need to create a new WOComponent. Or just a class file that
>> extends from WOComponent.
>>
>> Then override the appendToResponse and set the response content to
>> the data that you want to return. The tricky part is setting the
>> mime type correctly.
>>
>>
>> public void appendToResponse(WOResponse response, WOContext context) {
>> super.appendToResponse(response, context);
>> NSData content = yourDownloadableData();
>> if (content != null) {
>> response.setContent(content);
>> response.setHeader(new String("inline; filename=\"" +
>> "thefilename.ext" + "\""), new String("content-disposition"));
>> response.setHeader(Integer.toString(content.length()), new
>> String("content-length"));
>> response.setHeader(new String("CORRECTMIMETYPE; name=\"" +
>> "thefilename.ext" + "\""), new String("content-type"));
>> }
>> }
>>
>>
>> .steve
>>
>>
>>
>>
>> On Mar 24, 2004, at 9:37 AM, James Cicenia wrote:
>>
>>> Hello -
>>>
>>> Well for better or for worse I have decided to save my documents in
>>> the
>>> database.
>>> I made two EOs for this.. one to list them and then one to hold the
>>> actual BLOB.
>>> I am using mySQL for this.
>>>
>>> I have successfully uploaded the file into the database. I now have a
>>> page that lists
>>> the files. I then created a hyperlink to bind to my download method:
>>>
>>> public NSData downloadableData() {
>>> NSData downloadable = null;
>>> try {
>>> downloadable =
>>> theDocumentItem.projectDocumentObject().documentObject();
>>> } catch (NullPointerException npe) {
>>> System.err.println("Error: " + npe);
>>> }
>>> return downloadable;
>>> }
>>>
>>>
>>> This however always gives me ClassCastException. Any thoughts?
>>>
>>> Thanks,
>>> James Cicenia
>>> _______________________________________________
>>> 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.
>>>
>>>
>>>
>>
>>
>>
>> ///---------------------------------------
>> steve stout
>> web coordinator
>> arizona student unions
>> 52o.626.o1o9
>>
>> http://www.union.arizona.edu
>> _______________________________________________
>> 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.
> _______________________________________________
> 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.
>
>
--
Sincerely,
Robert Walker
_______________________________________________
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.