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 protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com
This email sent to [email protected]