Vous êtes sur la page 1sur 3

Uploading File into server from local machine

Hi
Friends, I just inform to you that, the following article is published by mukul's, but even though i
want to publish this article for my friends and dearest one's.

Through my OAF page i want to upload the file from local to server.

Step 1: Create the page with two items

a. MessageFileUpload Bean
b. Submit Button.
Step 2: Now write the below logic in the controller class

public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)


{
super.processFormRequest(pageContext, webBean);
if(pageContext.getParameter("Submit")!=null)
{
upLoadFile(pageContext,webBean);
}
}
public void upLoadFile(OAPageContext pageContext,OAWebBean webBean)
{
System.out.println("Action Performed");

String filePath =
pageContext.getProfile("FILE_UPLOAD_PATH");

System.out.println("Default File Path---->"+filePath);

String fileUrl = null;

try

DataObject fileUploadData =
pageContext.getNamedDataObject("FileUploading"); //FileUploading is my
MessageFileUpload Bean Id

if(fileUploadData!=null)
{

System.out.println("BeanId is also Not null");

String uFileName =
(String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME"); // include this
line
String contentType = (String)
fileUploadData.selectValue(null, "UPLOAD_FILE_MIME_TYPE"); // For Mime Type

System.out.println("User File Name---->"+uFileName);

FileOutputStream output = null;

InputStream input = null;

System.out.println("am In try block---->");

BlobDomain uploadedByteStream =
(BlobDomain)fileUploadData.selectValue(null, uFileName);
System.out.println("uploadedByteStream----
>"+uploadedByteStream);
// File file = new
File("/export_home_dev/user/oracle", uFileName); //once you deploy the page
uncomment this line and give your server path according to your fish
File file = new File("D:\\santhosh", uFileName); //
comment this line once you deploy the page into server
System.out.println("File output---->"+file);

// output = new
FileOutputStream("D:\\Kumar"+uFileName);

output = new FileOutputStream(file);

System.out.println("output----->"+output);

input = uploadedByteStream.getInputStream();

System.out.println("input---->"+input);
byte abyte0[] = new byte[0x19000];
int i;

while((i = input.read(abyte0)) > 0)


output.write(abyte0, 0, i);

//
output.write(uploadedByteStream.getBytes(0,(int)uploadedByteStream.getLength(
)));
output.close();
input.close();
// fileUrl = (String)file;
}
}
catch(Exception ex)
{
throw new OAException(ex.getMessage(),
OAException.ERROR);

}
Step 4: Now Run the page and see the output.

Step 5: Before going to see the output, i will show you, in my local mahcine i don't have file
called
"BT_GEOCode_Order_To_Cash.xls" file

Step 6: Now Run the page and Browse the file

Step 7: Now check the Browsed file called "BT_GEOCode_Order_To_Cash.xls" file in the local
machine

Note: This application is working in local machine only , because i gave my local path for the
saving purpose, so if you want to save the file from local to server, then you need to do the
following things

a. First change the local path to server path


b. then deploy the page and related .class and .server files from local to server
c. now run the page in the application not in the local machine(jdeveloper).

Vous aimerez peut-être aussi