File Upload
First, create a temporary View Object (View Object) for storing attachments, including the View Attribute of the Blob type, create a page that contains the messageFileUpload type Item, and create a page controller.
Write the following code in processFormRequest of the controller:
Try
{
OAViewObject vo = (OAViewObject) am. findViewObject ("FileVO1 ");
Row row = vo. getCurrentRow ();
String filePath = "/u01/demo10/demo10comn/temp /";
BlobDomain blob = (BlobDomain) row. getAttribute ("FileData ");
File f = new File (filePath + (String) row. getAttribute ("FileName "));
InputStream is = blob. getBinaryStream ();
FileOutputStream fos = new FileOutputStream (f );
Int size = blob. getBufferSize ();
Byte [] buffer = new byte [size];
Int len;
While (len = is. read (buffer ))! =-1)
{
Fos. write (buffer, 0, len );
}
Is. close ();
Fos. flush ();
Fos. close ();
}
Catch (IOException ex)
{
Ex. printStackTrace ();
System. out. println (ex. getMessage ());
}
File Download
The function is to automatically open the attachment save dialog box when you click the attachment link. The Code is as follows:
Try
{
OAViewObject vo = (OAViewObject) am. findViewObject ("FileVO1 ");
Row row = vo. getCurrentRow ();
BlobDomain blob = (BlobDomain) row. getAttribute ("FileData ");
HttpServletResponse response = (HttpServletResponse) pageContext. getRenderingContext (). getServletResponse ();
Response. addHeader ("Content-Disposition", "attachment; filename =" + (String) row. getAttribute ("FileName "));
Response. setContentType ("application/x-msdownload ");
InputStream is = blob. getBinaryStream ();
Int size = blob. getBufferSize ();
Byte [] buffer = new byte [size];
Int len;
While (len = is. read (buffer ))! =-1)
{
Response. getOutputStream (). write (buffer, 0, len );
}
Is. close ();
Response. getOutputStream (). flush ();
Response. getOutputStream (). close ();
}
Catch (IOException ex)
{
Ex. printStackTrace ();
System. out. println (ex. getMessage ());
}
Author: "Soy Milk"