Wednesday, December 11, 2013

File Upload in Oaf

File Upload in Oaf


                DataObject fileUploadData =
                    (DataObject)pageContext.getNamedDataObject("upload");
                String uFileName = "";
                //Destination file upload path
                String v_dirpath =  pageContext.getParameter("P_FILE_DIR");   //Change it to local directory              
                if (null != v_dirpath && null != fileUploadData) {
                    uFileName =
                            (String)fileUploadData.selectValue(null, "UPLOAD_FILE_NAME");
                    String contentType =
                        (String)fileUploadData.selectValue(null,
                                                           "UPLOAD_FILE_MIME_TYPE");
                }
                BlobDomain uploadedByteStream =
                    (BlobDomain)fileUploadData.selectValue(null, uFileName);
                File file =
                    new File(v_dirpath, uFileName.replaceAll(v_uploadfile_name,
                                                             v_uploadfile_formated));
                try {
                    FileOutputStream output = new FileOutputStream(file);
                    InputStream input = uploadedByteStream.getInputStream();
                    for (int bytes = 0; bytes < uploadedByteStream.getLength();
                         bytes++) {
                        output.write(input.read());
                    }
                    trx.commit();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                 
                    throw new OAException("The File has been uploaded Successfully....",
                                          OAException.CONFIRMATION);
                }

No comments:

Post a Comment