In this article we shall see OAF capability of uploading any
file into EBS file system(with application owner user credentials). Very bad
user can bring down the system as well, by uploading junk files .
We shall create below components for making this utility to
work:-
1.
OAF Page(\xxcust\oracle\apps\fnd\util\webui\XxcustFileUploadPG)
to capture user entered details like
a.
Destination directory
b.
Local File to be uploaded.
2.
OAF Controller(xxcust.oracle.apps.fnd.util.webui.XxcustFileUploadCO)
for page created in Step-1
3.
Function, Menu and responsibility for accessing
the page.
OAF Page for Upload
OAF
upload page is very simple page with
ü
MessageTextInput for “Directory”
ü
“MessageFileUpload” for selecting the local file
with “browse” button
ü
“Submit” button for final submission for
uploading.
Page
looks like below (code can be downloaded from the link provided at the end of the
post):-
OAF Controller
Controller
has code for reading the local file and uploading the same to server.
Following
is the method for uploading the selected local file, call this method from processFormRequest
method on click of “Submit” button
public void upLoadFile(OAPageContext pageContext,OAWebBean webBean)
{
String filePath = "";
System.out.println("Default File
Path---->"+filePath);
String fileUrl = null;
try
{
DataObject fileUploadData = pageContext.getNamedDataObject("MessageFileUpload");
//FileUploading is my MessageFileUpload Bean Id
if(fileUploadData!=null)
{
String uFileName = (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
String contentType = (String) fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE");
pageContext.writeDiagnostics(this,"User File
Name---->"+uFileName,OAFwkConstants.STATEMENT);
FileOutputStream output = null;
InputStream input = null;
BlobDomain uploadedByteStream =
(BlobDomain)fileUploadData.selectValue(null, uFileName);
pageContext.writeDiagnostics(this,"uploadedByteStream---->"+uploadedByteStream,OAFwkConstants.STATEMENT);
String directory = pageContext.getParameter("directory");
File file = new File(directory, uFileName);
pageContext.writeDiagnostics(this,"File output---->"+file,OAFwkConstants.STATEMENT);
output = new FileOutputStream(file);
pageContext.writeDiagnostics(this,"output----->"+output,OAFwkConstants.STATEMENT);
input = uploadedByteStream.getInputStream();
pageContext.writeDiagnostics(this,"input---->"+input,OAFwkConstants.STATEMENT);
byte abyte0[] = new byte[0x19000];
int i;
while((i = input.read(abyte0)) > 0){
output.write(abyte0, 0, i);
}
output.close();
input.close();
}
throw new OAException("File Uploaded
Successfully!",OAException.CONFIRMATION);
}
catch(Exception ex)
{
throw new OAException(ex.getMessage(), OAException.ERROR);
}
}
Invocation
from processFormRequest:-
public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
{
super.processFormRequest(pageContext, webBean);
if(pageContext.getParameter("Submit")!=null)
{
upLoadFile(pageContext,webBean);
}
}
Following
are the screenshots of utility in action:-
After
uploading file successfully
When
error occurs during file upload
Function Creation
Screenshots
for function creation:-
HTML
Call in “Web HTML” should be “OA.jsp?page=/xxcust/oracle/apps/fnd/util/webui/XxcustFileUploadPG”
Menu & Responsibility creation
This
section I leave to the reader.
You can
download OAF Page and controller class from here.
No comments:
Post a Comment