Re: Securing File System Resources ?
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