• 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: Securing File System Resources ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Securing File System Resources ?


  • Subject: Re: Securing File System Resources ?
  • From: Davin <email@hidden>
  • Date: Mon, 12 Dec 2005 22:11:14 -0800 (PST)

4.) Use a component action.

Wrap a hyperlink in a conditional making the hyperlink
available to only authenticated users. Bind the
hyperlink to a component action which downloads the
file:

import java.io.*;

String filePath;

WOActionResults downloadFile() {
	try
	{
		filePath =
getFilePathForCurrentResourceToDownload();
		WOResponse response = new WOResponse();
		String contentType =
WOApplication.application().resourceManager().contentTypeForResourceNamed(filepath);
		response.setHeader(contentType, "content-type");
		File f = new File(filepath);
		int bufferSize = (f.length() < 1024*1024) ? (int)
f.length() : 1024*1024;
		response.setContentStream(new FileInputStream(f),
bufferSize, (int) f.length());
		String fileName = NSPathUtilities.lastPathComponent(
filepath );
		response.setHeader("filename="+fileName,
"content-disposition");
		return response;
	}
	catch (Exception e)
	{
		WOResponse response = new WOResponse();
		response.appendContentString("Error downloading
file: " + e);
		return response;
	}
}

Davin.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
 _______________________________________________
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

  • Follow-Ups:
    • Re: Securing File System Resources ?
      • From: Dov Rosenberg <email@hidden>
  • Prev by Date: Fun with Primitives
  • Next by Date: Re: Securing File System Resources ?
  • Previous by thread: Re: Securing File System Resources ?
  • Next by thread: Re: Securing File System Resources ?
  • Index(es):
    • Date
    • Thread