GetMimeType()
Hi Everyone!,
I want to upload any random file into my table in form of BLOB and simultaneously want to fill the respective another column with its MimeType. Earlier I used Oracle Apex for this, but due to my new requirement I need to make this happen with the help of PL SQL and/or Forms. Could you add some input in this? If you could put example also then it would be awesome.
Thanks
Harbinder
There are (Java) procedures that check the mime type, but they almost all rely on known file extension names. It is practically impossible to check the contents of a file to see what the mime type is. I use this procedure:
function get_mime_type(i_filename in varchar2)
return varchar2
is
cursor c_mte(b_ext in varchar2) is
select mime_type
from a_mime_types
where file_extension = lower(b_ext);
v_file_extension a_mime_types.file_extension%type;
v_mime_type a_mime_types.mime_type%type;
begin
v_file_extension := substr(i_filename,instr(i_filename,'.',-1));
open c_mte (v_file_extension);
fetch c_mte into v_mime_type;
close c_mte;
return v_mime_type;
end get_mime_type;where the table is defined like this:
a_mime_types
mte_id number(10) not null,
file_extension varchar2(10 byte) not null,
mime_type varchar2(100 byte) not null
) [here|http://www.feedforall.com/mime-types.htm] So, when you upload a file, call this function too.
Oh, I got my mime types list here .
Edited by: InoL on Dec 8, 2009 2:09 PM
Similar Messages
-
String getMimeType(String file)
String getMimeType(String file)
in that what is the file exactly,which file is that, is it in the exploded directroy or some thing else
please help meIt's the name file (or with the relative path ) of the file that reside on the context path of the web aplication (in the servlet container where it is deployed).
-
FacesContext ,getMimeType,setContentType
I need to know the mimetype of a know file to doanload it, how can I do this?
I need this response.setContentType(file.type);
Edited by: dimis on Dec 10, 2009 2:00 AMIf you're using JSF 2.0, then you can call ExternalContext.getMimeType().
If you're using a version of JSF prior to 1.2, then you'll need to call ExternalContext.getContext() and downcast to ServletContext and call getMimeType() from there. -
OrdDoc.getMimeType() null
The following doc is loaded successfully and later added to the database successfully, but for some reason the mime type is always null. Any ideas?
OrdDoc doc = (OrdDoc) rset.getORAData(1, OrdDoc.getORADataFactory());
doc.loadDataFromFile(path + mf.getRef());
System.out.println(doc.getMimeType()); // nullHi Mavris
Thanks for the reply.
In my example the reason i did not invoke setProperties() method is because the setProperties method exposed in OrdDoc class is not same as the setProperties method in OrdAudio or OrdImage.
In OrdDoc class setProperties(byte[][] ctx,boolean setComments) takes two arguments where as setProperties() in OrdAudio and OrdImage does not take any arguments.
byte[ ] ctx[ ] = new byte [4000][1];
When i tried to use setProperties(ctx,true) in OrdDoc i was getting an error.
Can you please tell if this is the correct way to invoke setProperties on OrdDoc in Java Program?
Regarding the list of format that Intermedia Understands, the Appendices A, B and C in Intermedia Refererence talks only about Audio, Image and Video. It doesnt have any details about Document (pdf, txt, doc) files. Can you please tell where can i look for the list of formats that intermedia understands for OrdDoc?
Since the dataType is OrdDoc in my table. How do i check the LOB length?
I tried it using Intermedia Java API by calling getContentLength method after retreiving the OrdDoc column from resultset but it has a value of '0'. So am not sure why the document is not getting loaded.
Please help me resolve this issue.
Thanks -
DOC.getMimeType() is null
Hello Gurus,
Getting DOC.getMimeType() as null when using ORADOC after Import , Unable to find the document type.
Importing is done through a URL using ordsys.orddoc.import(), the filename is an ID, we call the document using that ID, will not know the filetype until Opened.
Any Suggestions.
Thank youSorry Its ORDDOC not ORADOC
-
Error while processing a response
Hi, i have the next error while my class is processing the response. The
error is:
java.lang.NoSuchMethodError at
com.bea.portal.appflow.servlets.internal.PortalWebflowServlet.doGet(PortalWe
bflowServlet.java:214) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853) at ...
My class only retrieve a param by request and send to response a image
archive from a DB. The code is:
response.setContentType(img.getMimetype().trim());
response.setHeader("Content-disposition","attachment; filename=\"" +
img.getNombre().trim()+"\"");
response.setHeader("Cache-Control", "no-cache");
response.setContentLength(img.getTamanoBytes());
try {
ServletOutputStream servletoutputstream =
response.getOutputStream();
servletoutputstream.write(buffer);
servletoutputstream.flush();
servletoutputstream.close();
catch (IOException ex3) {
throw new ProcessingException(ex3.toString());
The "img" object contains my image properties and the "buffer" variable
contains the byte array with the image.
Has anybody idea whats happening??
Thanks in advance.Hi Sambo44,
Thanks for your posting!
I am not totally understanding your meaning. How did you get this error?Did you want to login on Azure form your VS? From your error message, I am not sure you can login on Azure portal using your account. Please make sure your account is right.
Or did you try to use ACS or WIF in your project for authorization? If it is , I suggest you can post this issue on Azure AD forum for more details.
Any question about this issue, please feel free to let me know.
Regards,
Will
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
FILE UPLOAD PROBLEM SHOWING THE CONTENTS IN THE SAME BROWSER WINDOW
Hi,
This is amit Joshi
I have uploaded content using input tag of type file and posted to jsp as multipart/form-data type
in that jsp i am using following code to display the content in browser but only first content is displayed How can i modify it to show all content in the file ..
<html>
<head>
<title>File Upload Display</title>
</head>
<body>
<%
//ServletOutputStream sout=response.getOutputStream();
StringBuilder strBuilder = new StringBuilder();
int count=0;
String f;
f=request.getParameter("filedb");
DBManager dbm = new DBManager();
//dbm.createTable("mms3");
//log.info("In JSP : "+ f);
//dbm.insert_data(f,"mms3");
%>
<%
if (ServletFileUpload.isMultipartContent(request)){
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);
strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
String optionalFileName = "";
FileItem fileItem = null;
Iterator it = fileItemsList.iterator();
ServletOutputStream outputStream=null;
while (it.hasNext()){
FileItem fileItemTemp = (FileItem)it.next();
if (fileItemTemp.isFormField()){
%>
<b>Name-value Pair Info:</b>
Field name: <%= fileItemTemp.getFieldName() %>
Field value: <%= fileItemTemp.getString() %>
<%
if (fileItemTemp.getFieldName().equals("filename"))
optionalFileName = fileItemTemp.getString();
else
fileItem = fileItemTemp;
if (fileItem!=null){
String fileName = fileItem.getName();
%>
<b>Uploaded File Info:</b>
Content type: <%= fileItem.getContentType() %>
Field name: <%= fileItem.getFieldName() %>
File name: <%= fileName %>
<%
if(fileItem.getContentType().equals("image/jpeg")) { %>
File : <p><%
//response.setContentType("image/gif");
byte[] bArray=fileItem.get();
response.setContentType("image/jpeg");
outputStream=null;
outputStream= response.getOutputStream();
outputStream.write(bArray);
outputStream.flush();
outputStream.close();
else if(fileItem.getContentType().equals("text/plain"))
%> File : <%= fileItem.getString() %>
<%
byte[] bArray=fileItem.get();
response.setContentType("text/plain");
outputStream = response.getOutputStream();
out.println();
outputStream.write(bArray);
outputStream.flush();
outputStream.close();
%> </p> <%
%>
</body>
</html>
Edited by: Amit_Joshi on Nov 13, 2007 10:58 PMWell Well Well..
That would not work...
What you have to do is save the uploaded file content on to a location and then pass the fileName as a request parameter to a deidicated which displays the contents of that file.
Just as an example
<html>
<head>
<title>File Upload Display</title>
</head>
<body>
<%
//ServletOutputStream sout=response.getOutputStream();
StringBuilder strBuilder = new StringBuilder();
int count=0;
String f;
f=request.getParameter("filedb");
DBManager dbm = new DBManager();
//dbm.createTable("mms3");
//log.info("In JSP : "+ f);
//dbm.insert_data(f,"mms3");
%>
<%
if (ServletFileUpload.isMultipartContent(request)){
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);
strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
String optionalFileName = "";
FileItem fileItem = null;
Iterator it = fileItemsList.iterator();
ServletOutputStream outputStream=null;
while (it.hasNext()){
FileItem fileItemTemp = (FileItem)it.next();
%>
Name-value Pair Info:
Field name: <%= fileItemTemp.getFieldName() %><br/>
Field value: <%= fileItemTemp.getString() %><br/>
<%
if (fileItemTemp.getFieldName().equals("filename"))
optionalFileName = fileItemTemp.getString();
if(!fileTempItem.isFormFiled()){
String fileName = fileItem.getName();
fileItem.write(optionalFileName);
%>
Uploaded File Info:
Content type: <%= fileItem.getContentType() %><br/>
Field name: <%= fileItem.getFieldName() %><br/>
File name: <%= fileName %><br/>
<%
if(fileItem.getContentType().equals("image/jpeg") || fileItem.getContentType().equals("image/pjeg")) {
%>
<img src="FileServlet?fileName=<%=optionalFileName%>"
<%
%>
</body>
</html>a sample code snippet for FileServlet.
String fileName = request.getParameter(fileName);
File file = new File(fileName);
if(!file.exists())
return;
// If JSP
String mimeType = application.getMimeType("fileName");
If you are using servlet
String mimeType = this.getServletContext().getMimeType(fileName);
response.setContentType(mimeType);
response.setHeader("Content-Disposition","inline;filename=\\"+fileName+"\\");
BufferedOutputStream out1 = null;
InputStream in = null;
if(mimeType == null)
mimeType = "application/octet-stream";
try{
in = new FileInputStream(f);
response.setContentLength(in.available());
BufferedOutputStream out1 = new BufferedOutputStream(response.getOutputStream(),1024);
int size = 0;
byte[] b = new byte[1024];
while ((size = in.read(b, 0, 1024)) > 0)
out1.write(b, 0, size);
}catch(Exception exp){
}finally{
if(out1 != null){
try{
out1.flush();
out1.close();
}catch(Exception e){}
if(in != null){
try{in.close();}catch(Exception e){}
} Hope that might answer your question :)
However,this is not the recommended way of doing this make use of MVC pattern.Would be a better approach.
you might think of googling on this and can findout what is the best practise followed for problems of this sort
REGARDS,
RaHuL -
Hi all,
I am developing an application but there is a error in my code i culdnt find so far. Can anyone help?
I want to write to a .xml file in web server with servlet from remote. My code is
private static String message = "Error during Servlet processing";
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// response.setContentType("text/html;charset=UTF-8");
try {
int len = request.getContentLength();
byte[] input = new byte[len];
ServletInputStream sin = request.getInputStream();
int c, count = 0;
while ((c = sin.read(input, count, input.length - count)) != -1) {
count += c;
sin.close();
String inString = new String(input);
int index = inString.indexOf("/n");
if (index == -1) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(message);
response.getWriter().close();
return;
String user = inString.substring(0, index);
String data = inString.substring(index + 2);
//decode application/x-www-form-urlencoded string
// String decodedUser = URLDecoder.decode(user, "UTF-8");
// String decodedData = URLDecoder.decode(data, "UTF-8");
// int i = decodedData.indexOf("/n");
// String user = decodedData.substring(0, i);
// String db = decodedData.substring(i + 2, decodedData.length());
String result = "no";
// response.setContentType("text/html");
String filename = "/WEB-INF/" + user + ".xml";
// String pathName = getServletContext ( ) .getRealPath ( "/" + filename ) ;
// String contentType = getServletContext ( ) .getMimeType ( pathName ) ;
// if ( contentType != null )
// response.setContentType ( contentType ) ;
// else
// response.setContentType ( "application/octet-stream" ) ;
try {
OutputStream fcheck = null;
byte[] buf = data.getBytes();
fcheck = new FileOutputStream(filename);
for (int i = 0; i < buf.length; i++) {
fcheck.write(buf);
result = "yes";
} catch (IOException ex) {
Logger.getLogger(UpdateDB.class.getName()).log(Level.SEVERE, null, ex);
result = "no";
// ServletContext context = getServletContext();
// set the response code and write the response data
response.setStatus(HttpServletResponse.SC_OK);
OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
writer.write(result);
writer.flush();
writer.close();
} catch (IOException e) {
try {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(e.getMessage());
response.getWriter().close();
} catch (IOException ioe) {
ý am sending data from remote as a string and want to write it in xml. But it is not working. Where am i wrong?I fixed it. But now it doesnt write to file and there is no error. So i cant find where am a wrong.
I send a request, it is taking string but it is not writing to file eventhough it is entering the try block.
Why it isnt writing? Is not servlet let it to write to file. My working code is here
private static String message = "Error during Servlet processing";
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try {
int len = request.getContentLength();
byte[] input = new byte[len];
ServletInputStream sin = request.getInputStream();
int c, count = 0;
while ((c = sin.read(input, count, input.length - count)) != -1) {
count += c;
sin.close();
String inString = new String(input);
int index = inString.indexOf("/n");
if (index == -1) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(message);
response.getWriter().close();
return;
String user = inString.substring(0, index);
String data = inString.substring(index + 2);
//decode application/x-www-form-urlencoded string
// String decodedUser = URLDecoder.decode(user, "UTF-8");
String decodedData = URLDecoder.decode(data, "UTF-8");
// int i = decodedData.indexOf("/n");
// String user = decodedData.substring(0, i);
// String db = decodedData.substring(i + 2, decodedData.length());
String result = "no";
String filename = user + ".xml";
try {
OutputStream fcheck = null;
byte[] buf = decodedData.getBytes();
fcheck = new FileOutputStream(filename);
for (int i = 0; i < buf.length; i++) {
fcheck.write(buf);
// char buffer[]=new char[data.length()];
// data.getChars(0, data.length(), buffer, 0);
// FileWriter f0=new FileWriter(filename);
// for(int i=0;i<buffer.length;i++){
// f0.write(buffer[i]);
result = "yes";
} catch (IOException ex) {
Logger.getLogger(UpdateDB.class.getName()).log(Level.SEVERE, null, ex);
result = "no";
// ServletContext context = getServletContext();
// set the response code and write the response data
response.setStatus(HttpServletResponse.SC_OK);
OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
writer.write(result);
writer.flush();
writer.close();
} catch (IOException e) {
try {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(e.getMessage());
response.getWriter().close();
} catch (IOException ioe) { -
How do i use java printing api 1.4
How can i print documents using jdk1.4 api.
I have used the following program for printing.
import java.io.*;
import java.awt.*;
import java.awt.print.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
public class Print2DtoStream implements Printable{
public Print2DtoStream() {
/* Use the pre-defined flavor for a Printable from an InputStream */
DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
/* Specify the type of the output stream */
String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType();
/* Locate factory which can export a GIF image stream as Postscript */
StreamPrintServiceFactory[] factories =
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, psMimeType);
if (factories.length == 0) {
System.err.println("No suitable factories");
System.exit(0);
try {
/* Create a file for the exported postscript */
FileOutputStream fos = new FileOutputStream("out.ps");
/* Create a Stream printer for Postscript */
StreamPrintService sps = factories[0].getPrintService(fos);
/* Create and call a Print Job */
DocPrintJob pj = sps.createPrintJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
Doc doc = new SimpleDoc(this, flavor, null);
pj.print(doc, aset);
fos.close();
} catch (PrintException pe) {
System.err.println(pe);
} catch (IOException ie) {
System.err.println(ie);
public int print(Graphics g,PageFormat pf,int pageIndex) {
if (pageIndex == 0) {
Graphics2D g2d= (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
g2d.setColor(Color.black);
g2d.drawString("example string", 250, 250);
g2d.fillRect(0, 0, 200, 200);
return Printable.PAGE_EXISTS;
} else {
return Printable.NO_SUCH_PAGE;
public static void main(String args[]) {
Print2DtoStream sp = new Print2DtoStream();
However when i run this program,it prints "example string" as used in g2d.drawString("example string",250,250) method above.
What if i want to print content from any file.
So anybody konwing this plz replyThis is covered pretty well in the Java Print Service API Guide.
You could start here http://java.sun.com/j2se/1.4.1/docs/guide/jps/spec/printing.fm1.html
Basically, you have two choices - either you're going to throw a document at the print service, or you're going to print using Graphics2D commands. You also have the choice between printing to a printer, or to a stream. Mix and match for four combinations.
Whether you can just take a raw document and send it to a printer via the document printing stuff depends on what print services you have installed. For the standard J2SE, it's pretty limited.
If you're doing it via the Graphics2D approach, however, you can print anything you can draw. That's nice - it means you can use the same code to display stuff on the screen and print it. -
How to drag and drop a file with its Systemfile icon to a Jtext area
I want to drag and drop a file to a JText area with its system file icon , but the problem is I cant show the file icon.
Anyone knows this.
this is my code.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
public class FileDrag extends JFrame implements DropTargetListener {
DropTarget dt;
File file;
JTextArea ta;
JLabel lbl;
Graphics g;
ImageIcon tmpIcon;
public FileDrag() {
super("Drop Test");
setSize(300, 300);
getContentPane().add(
new JLabel("Drop a list from your file chooser here:"),
BorderLayout.NORTH);
ta = new JTextArea();
ta.setBackground(Color.white);
getContentPane().add(ta);
dt = new DropTarget(ta, this);
setVisible(true);
public void dragEnter(DropTargetDragEvent dtde) {
System.out.println("Drag Enter");
public void dragExit(DropTargetEvent dte) {
System.out.println("Source: " + dte.getSource());
System.out.println("Drag Exit");
public void dragOver(DropTargetDragEvent dtde) {
System.out.println("Drag Over");
public void dropActionChanged(DropTargetDragEvent dtde) {
System.out.println("Drop Action Changed");
public void drop(DropTargetDropEvent dtde) {
FileSystemView view = FileSystemView.getFileSystemView();
JLabel testb;
Icon icon = null;
Toolkit tk;
Dimension dim;
BufferedImage buff = null;
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
System.out.println("Possible flavor: " + flavors.getMimeType());
if (flavors[i].isFlavorJavaFileListType()) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
ta.setText("Successful file list drop.\n\n");
java.util.List list = (java.util.List) tr.getTransferData(flavors[i]);
for (int j = 0; j < list.size(); j++) {
System.out.println(list.get(j));
file = (File) list.get(j);
icon = view.getSystemIcon(file);
ta.append(list.get(j) + "\n");
ta.append("\n");
tk = Toolkit.getDefaultToolkit();
dim = tk.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(ta, buff.getGraphics(), 10, 10);
repaint();
dtde.dropComplete(true);
return;
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace();
dtde.rejectDrop();
public static void main(String args[]) {
new FileDrag();I want to drag and drop a file to a JText area with its system file icon , but the problem is I cant show the file icon.
Anyone knows this.
this is my code.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileSystemView;
public class FileDrag extends JFrame implements DropTargetListener {
DropTarget dt;
File file;
JTextArea ta;
JLabel lbl;
Graphics g;
ImageIcon tmpIcon;
public FileDrag() {
super("Drop Test");
setSize(300, 300);
getContentPane().add(
new JLabel("Drop a list from your file chooser here:"),
BorderLayout.NORTH);
ta = new JTextArea();
ta.setBackground(Color.white);
getContentPane().add(ta);
dt = new DropTarget(ta, this);
setVisible(true);
public void dragEnter(DropTargetDragEvent dtde) {
System.out.println("Drag Enter");
public void dragExit(DropTargetEvent dte) {
System.out.println("Source: " + dte.getSource());
System.out.println("Drag Exit");
public void dragOver(DropTargetDragEvent dtde) {
System.out.println("Drag Over");
public void dropActionChanged(DropTargetDragEvent dtde) {
System.out.println("Drop Action Changed");
public void drop(DropTargetDropEvent dtde) {
FileSystemView view = FileSystemView.getFileSystemView();
JLabel testb;
Icon icon = null;
Toolkit tk;
Dimension dim;
BufferedImage buff = null;
try {
Transferable tr = dtde.getTransferable();
DataFlavor[] flavors = tr.getTransferDataFlavors();
for (int i = 0; i < flavors.length; i++) {
System.out.println("Possible flavor: " + flavors.getMimeType());
if (flavors[i].isFlavorJavaFileListType()) {
dtde.acceptDrop(DnDConstants.ACTION_COPY);
ta.setText("Successful file list drop.\n\n");
java.util.List list = (java.util.List) tr.getTransferData(flavors[i]);
for (int j = 0; j < list.size(); j++) {
System.out.println(list.get(j));
file = (File) list.get(j);
icon = view.getSystemIcon(file);
ta.append(list.get(j) + "\n");
ta.append("\n");
tk = Toolkit.getDefaultToolkit();
dim = tk.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
buff = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB);
icon.paintIcon(ta, buff.getGraphics(), 10, 10);
repaint();
dtde.dropComplete(true);
return;
System.out.println("Drop failed: " + dtde);
dtde.rejectDrop();
} catch (Exception e) {
e.printStackTrace();
dtde.rejectDrop();
public static void main(String args[]) {
new FileDrag(); -
Link Item Style to open a PDF hangs if opened in IE in 30 seconds
Hi,
I am using Jdeveloper version 9.0.3.
I have a page in which, I have an advanced table, in which there is a column, with item style - link.
On the link item there is a PPR event and it should open a PDF file, residing on the server.
I am using java code to open the PDF file.
In Internet Explorer, the link doesnt work, infact the Explorer hangs and the user has to exit the window.
This doesnt happen in Firefox. However, this is critical as , use of firefox is not allowed, and the users have to ultimately use IE.
Below is the java code for opening the PDF file from the server:
public void downloadFileFromServer(OAPageContext pageContext, String file_name_with_path, String file_name_with_ext)
HttpServletResponse response = (HttpServletResponse) pageContext.getRenderingContext().getServletResponse();
if (file_name_with_path == null || "".equals(file_name_with_path)){
throw new OAException("File path is invalid.");
File fileToDownload = null;
try{
fileToDownload = new File(file_name_with_path);
}catch (Exception e){
throw new OAException("Invalid File Path or file does not exist.");
if (!fileToDownload.exists()){
throw new OAException("File does not exist.");
if (!fileToDownload.canRead()){
throw new OAException("Not Able to read the file.");
String fileType = getMimeType(file_name_with_ext);
response.setContentType(fileType);
response.setContentLength((int)fileToDownload.length());
response.setHeader("Content-Disposition", "attachment; filename=\"" + file_name_with_ext + "\"");
InputStream in = null;
ServletOutputStream outs = null;
try{
outs = response.getOutputStream();
in = new BufferedInputStream(new FileInputStream(fileToDownload));
int ch;
while ((ch = in.read()) != -1){
outs.write(ch);
}catch (IOException e){
e.printStackTrace();
}finally{
try{
outs.flush();
outs.close();
if (in != null){
in.close();
}catch (Exception e){
e.printStackTrace();
}//end catch
}//end finally
}//end method
public String getMimeType(String s)
int i = s.lastIndexOf(".");
if (i > 0 && i < s.length() - 1){
String s1 = s.substring(i + 1);
if (s1.equalsIgnoreCase("pdf")){
return "application/pdf";
}//end if
}//end if
return "application/octet-stream";
}//end method
Thanks,
AJHi Kristofer,
We did look at the possibility for using messageDownload bean instead of a link, but we do not want to store the file as a LOB.
The file needs to be stored in the server location.
Any clue as to why the file opened in the browser ( on clicking on the link) hangs and this is happening only in IE.
Thanks,
AJ -
Need help with my HttpConnection From Midlet To Servlet...
NEED HELP ASAP PLEASE....
This class is supposed to download a file from the servlet...
the filename is given by the midlet... and the servlet will return the file in bytes...
everything is ok in emulator...
but in nokia n70... error occurs...
Http Version Mismatch shows up... when the pout.flush(); is called.. but when removed... java.io.IOException: -36 occurs...
also i have posted the same problem in nokia forums..
please check also...
http://discussion.forum.nokia.com/forum/showthread.php?t=105567
now here are my codes...
midlet side... without pout.flush();
public class DownloadFile {
private GmailMidlet midlet;
private HttpConnection hc;
private byte[] fileData;
private boolean downloaded;
private int lineNumber;
// private String url = "http://121.97.220.162:8084/ProxyServer/DownloadFileServlet";
private String url = "http://121.97.221.183:8084/ProxyServer/DownloadFileServlet";
// private String url = "http://121.97.221.183:8084/ProxyServer/Attachments/mark.ramos222/GmailId111d822a8bd6f6bb/01032007066.jpg";
/** Creates a new instance of DownloadFile */
public DownloadFile(GmailMidlet midlet, String fileName) throws OutOfMemoryError, IOException {
System.gc();
setHc(null);
OutputStream out = null;
DataInputStream is= null;
try{
setHc((HttpConnection)Connector.open(getUrl(), Connector.READ_WRITE));
} catch(ConnectionNotFoundException ex){
setHc(null);
} catch(IOException ioex){
ioex.printStackTrace();
midlet.alertScreen = new AlertScreen("Error C1", ioex.toString(),
null, AlertType.ERROR);
midlet.alertScreen.setTimeout(Alert.FOREVER);
midlet.display.setCurrent(midlet.alertScreen);
try {
if(getHc() != null){
getHc().setRequestMethod(HttpConnection.POST);
getHc().setRequestProperty("Accept","*/*");
getHc().setRequestProperty("Http-version","HTTP/1.1");
lineNumber = 1;
getHc().setRequestProperty("CONTENT-TYPE",
"text/plain");
lineNumber = 2;
getHc().setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.1");
lineNumber =3;
out = getHc().openOutputStream();
lineNumber = 4;
PrintStream pout = new PrintStream(out);
lineNumber = 5;
pout.println(fileName);
lineNumber = 6;
// pout.flush();
System.out.println("File Name: "+fileName);
lineNumber = 7;
is = getHc().openDataInputStream();
long len = getHc().getLength();
lineNumber = 8;
byte temp[] = new byte[(int)len];
lineNumber = 9;
System.out.println("len "+len);
is.readFully(temp,0,(int)len);
lineNumber = 10;
setFileData(temp);
lineNumber = 11;
is.close();
lineNumber = 12;
if(getFileData() != null)
setDownloaded(true);
else
setDownloaded(false);
System.out.println("Length : "+temp.length);
midlet.setAttachFile(getFileData());
lineNumber = 13;
pout.close();
lineNumber = 14;
out.close();
lineNumber = 15;
getHc().close();
} catch(Exception ex){
setDownloaded(false);
ex.printStackTrace();
midlet.alertScreen = new AlertScreen("Error C2+ line"+lineNumber,
ex.toString()+
" | ",
null, AlertType.ERROR);
midlet.alertScreen.setTimeout(Alert.FOREVER);
midlet.display.setCurrent(midlet.alertScreen);
public HttpConnection getHc() {
return hc;
public void setHc(HttpConnection hc) {
this.hc = hc;
public String getUrl() {
return url;
public void setUrl(String url) {
this.url = url;
public byte[] getFileData() {
return fileData;
public void setFileData(byte[] fileData) {
this.fileData = fileData;
public boolean isDownloaded() {
return downloaded;
public void setDownloaded(boolean downloaded) {
this.downloaded = downloaded;
}this is the midlet side with pout.flush();
showing Http Version Mismatch
public class DownloadFile {
private GmailMidlet midlet;
private HttpConnection hc;
private byte[] fileData;
private boolean downloaded;
private int lineNumber;
// private String url = "http://121.97.220.162:8084/ProxyServer/DownloadFileServlet";
private String url = "http://121.97.221.183:8084/ProxyServer/DownloadFileServlet";
// private String url = "http://121.97.221.183:8084/ProxyServer/Attachments/mark.ramos222/GmailId111d822a8bd6f6bb/01032007066.jpg";
/** Creates a new instance of DownloadFile */
public DownloadFile(GmailMidlet midlet, String fileName) throws OutOfMemoryError, IOException {
System.gc();
setHc(null);
OutputStream out = null;
DataInputStream is= null;
try{
setHc((HttpConnection)Connector.open(getUrl(), Connector.READ_WRITE));
} catch(ConnectionNotFoundException ex){
setHc(null);
} catch(IOException ioex){
ioex.printStackTrace();
midlet.alertScreen = new AlertScreen("Error C1", ioex.toString(),
null, AlertType.ERROR);
midlet.alertScreen.setTimeout(Alert.FOREVER);
midlet.display.setCurrent(midlet.alertScreen);
try {
if(getHc() != null){
getHc().setRequestMethod(HttpConnection.POST);
getHc().setRequestProperty("Accept","*/*");
getHc().setRequestProperty("Http-version","HTTP/1.1");
lineNumber = 1;
getHc().setRequestProperty("CONTENT-TYPE",
"text/plain");
lineNumber = 2;
getHc().setRequestProperty("User-Agent",
"Profile/MIDP-2.0 Configuration/CLDC-1.1");
lineNumber =3;
out = getHc().openOutputStream();
lineNumber = 4;
PrintStream pout = new PrintStream(out);
lineNumber = 5;
pout.println(fileName);
lineNumber = 6;
pout.flush();
System.out.println("File Name: "+fileName);
lineNumber = 7;
is = getHc().openDataInputStream();
long len = getHc().getLength();
lineNumber = 8;
byte temp[] = new byte[(int)len];
lineNumber = 9;
System.out.println("len "+len);
is.readFully(temp,0,(int)len);
lineNumber = 10;
setFileData(temp);
lineNumber = 11;
is.close();
lineNumber = 12;
if(getFileData() != null)
setDownloaded(true);
else
setDownloaded(false);
System.out.println("Length : "+temp.length);
midlet.setAttachFile(getFileData());
lineNumber = 13;
pout.close();
lineNumber = 14;
out.close();
lineNumber = 15;
getHc().close();
} catch(Exception ex){
setDownloaded(false);
ex.printStackTrace();
midlet.alertScreen = new AlertScreen("Error C2+ line"+lineNumber,
ex.toString()+
" | ",
null, AlertType.ERROR);
midlet.alertScreen.setTimeout(Alert.FOREVER);
midlet.display.setCurrent(midlet.alertScreen);
public HttpConnection getHc() {
return hc;
public void setHc(HttpConnection hc) {
this.hc = hc;
public String getUrl() {
return url;
public void setUrl(String url) {
this.url = url;
public byte[] getFileData() {
return fileData;
public void setFileData(byte[] fileData) {
this.fileData = fileData;
public boolean isDownloaded() {
return downloaded;
public void setDownloaded(boolean downloaded) {
this.downloaded = downloaded;
}here is the servlet side...
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if(request.getMethod().equals("POST")){
BufferedReader dataIN = request.getReader();
String fileName = dataIN.readLine();
File file = new File(fileName);
String contentType = getServletContext().getMimeType(fileName);
response.setContentType(contentType);
System.out.println("Content Type: "+contentType);
System.out.println("File Name: "+fileName);
int size = (int)file.length()/1024;
if(file.length() > Integer.MAX_VALUE){
System.out.println("Very Large File!!!");
response.setContentLength(size*1024);
FileInputStream fis = new FileInputStream(fileName);
byte data[] = new byte[size*1024];
fis.read(data);
System.out.println("data lenght: "+data.length);
ServletOutputStream sos = response.getOutputStream();
sos.write(data);
// out.flush();
}else{
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
BufferedReader dataIN = request.getReader();
String msg_uid = dataIN.readLine();
System.out.println("Msg_uid"+msg_uid);
JDBConnection dbconn = new JDBConnection();
String fileName = dbconn.getAttachment(msg_uid);
String[] fileNames = fileName.split(";");
int numFiles = fileNames.length;
out.println(numFiles);
for(int i = 0; i<numFiles; i++){
out.println(fileNames);
out.flush();
out.close();
Message was edited by:
Mark.Ramos2221) Have you looked up the symbian error -36 on new-lc?
2) Have you tried the example in the response on forum nokia?
3) Is the address "121.97.220.162:8084" accessible from the internet, on the device, on the specified port? -
Still have the same error messages
Hi Rajiv,
Thanks a lot for your help. I tried to load the java package
before I exported my images. The loading java worked sucessfully,
however the same error messages came out when I exported images.
Actually, I stored five JPEG images as ORDSYS.ORDImage in a table
for a test. Below is my image-loading codes and the images are
truely in the database since I proved it by running a
check-properties script.
-- This program will create a table called imgtable and import
-- five .jpg files into it. Also the status of the images will
-- be checked.
connect imgdemo/imgdemo;
set serveroutput on
set echo on
-- decomment for demo images
drop table imgtable;
create table imgtable (id number,
Image ORDSYS.ORDImage);
-- Insert a row with empty BLOB.
insert into imgtable values(1,ORDSYS.ORDImage.init());
-- Insert a row with empty BLOB.
insert into imgtable values(2,ORDSYS.ORDImage.init());
-- Insert a row with empty BLOB.
insert into imgtable values(3,ORDSYS.ORDImage.init());
-- Insert a row with empty BLOB.
insert into imgtable values(4,ORDSYS.ORDImage.init());
-- Insert a row with empty BLOB.
insert into imgtable values(5,ORDSYS.ORDImage.init());
--importimg.sql
set serveroutput on
set echo on
-- Import the two files into the database.
DECLARE
obj ORDSYS.ORDIMAGE;
ctx RAW(4000) := NULL;
BEGIN
-- This imports the image file img71.gif from the IMGDIR
directory
-- on a local file system (srcType=FILE) and sets the properties.
select Image into obj from imgtable where id = 1 for update;
obj.setSource('FILE','IMGDIR','1.jpg');
obj.import(ctx);
update imgtable set image = obj where id = 1;
commit;
-- This imports the image file img50.gif from the IMGDIR
directory
-- on a local file system (srcType=FILE) and sets the properties.
select Image into obj from imgtable where id = 2 for update;
obj.setSource('FILE','IMGDIR','2.jpg');
obj.import(ctx);
update imgtable set image = obj where id = 2;
commit;
select Image into obj from imgtable where id = 3 for update;
obj.setSource('FILE','IMGDIR','3.jpg');
obj.import(ctx);
update imgtable set image = obj where id = 3;
commit;
select Image into obj from imgtable where id = 4 for update;
obj.setSource('FILE','IMGDIR','4.jpg');
obj.import(ctx);
update imgtable set image = obj where id = 4;
commit;
select Image into obj from imgtable where id = 5 for update;
obj.setSource('FILE','IMGDIR','5.jpg');
obj.import(ctx);
update imgtable set image = obj where id = 5;
commit;
END;
-- chkprop.sql
set serveroutput on;
--connect imgdemo/imgdemo
--Query imgtable for ORDSYS.ORDImage.
DECLARE
image ORDSYS.ORDImage;
idnum integer;
properties_match BOOLEAN;
BEGIN
FOR I IN 1..5 LOOP
SELECT id into idnum from imgtable where id=I;
dbms_output.put_line('image id: '|| idnum);
SELECT Image into image from imgtable where id=I;
properties_match := image.checkProperties;
IF properties_match THEN DBMS_OUTPUT.PUT_LINE('Check Properties
Succeeded');
END IF;
dbms_output.put_line('image height: '|| image.getHeight);
dbms_output.put_line('image width: '|| image.getWidth);
dbms_output.put_line('image MIME type: '||
image.getMimeType);
dbms_output.put_line('image file format: '||
image.getFileFormat);
dbms_output.put_line('BLOB Length: '||
TO_CHAR(image.getContentLength));
dbms_output.put_line('-------------------------------------------');
END loop;
END;
The program that I used to export images is as follows:
-- retrive an image in the database and display it
connect internal;
CALL DBMS_JAVA.GRANT_PERMISSION (
'IMGDEMO',
'java.io.FilePermission',
'/home/oracle/img/test.dat',
'write');
CONNECT imgdemo/imgdemo;
SET SERVEROUTPUT ON
SET ECHO ON
create or replace directory imgdir
as '/home/oracle/img';
grant read on directory imgdir to public with grant option;
(line 1) DECLARE
src ORDSYS.ORDImage;
ctx RAW(4000) := NULL;
BEGIN
-- Select the desired photograph from the stockphotos table.
SELECT Image INTO src FROM imgtable WHERE id = 1;
ORDSYS.ORDIMAGE.export(src, ctx,'FILE','IMGDIR','test.dat');
EXCEPTION
WHEN OTHERS THEN
RAISE;
-- EXCEPTION
--WHEN ORDSYS.ORDSourceExceptions.METHOD_NOT_SUPPORTED THEN
-- DBMS_OUTPUT.put_line('Source METHOD_NOT_SUPPORTED caught');
--WHEN ORDSYS.ORDSourceExceptions.SOURCE_PLUGIN_EXCEPTION THEN
-- DBMS_OUTPUT.put_line('SOURCE PLUGIN EXCEPTION caught');
--WHEN OTHERS THEN
-- DBMS_OUTPUT.put_line('OTHER EXCEPTION caught');
END;
host ls -l ~/img/test.dat;
The error message is as follows:
ERROR at line 1:
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at "ORDSYS.ORDSOURCE", line 354
ORA-06510: PL/SQL: unhandled user-defined exception
ORA-06512: at line 13
I really tried everything to fix it and still doesn't work. I
guess maybe the export method is not implemented for intermedia.
Best regards,
KaiKai,
You're almost there! I apologize for not providing a complete
response previously. I thought the webiv note had sufficient
details on java file permissions.
For export to work, ORDSYS needs write permissions on the file
as well.
call DBMS_JAVA.GRANT_PERMISSION( 'ORDSYS',
'java.io.FilePermission',
'/home/oracle/img/test.dat',
'write');The interMedia documentation doesn't correctly describe all the
requirements for granting file write access using
DBMS_JAVA.GRANT_PERMISSION. You must
either grant write access to public, or to both a specific user
and the ORDSYS user name. For example, you might grant write
access to all files in all directories to ORDSYS and write access
to all files in a specific directory to SCOTT.
call DBMS_JAVA.GRANT_PERMISSION( 'ORDSYS',
'java.io.FilePermission',
'<<ALL FILES>>',
'read,write');
call DBMS_JAVA.GRANT_PERMISSION( 'SCOTT',
'java.io.FilePermission',
'D:\ordjava\test\data\*',
'read,write');See the security and performance section in Oracle Java
Developer's Guide and the java.io.FilePermission class in the
Java API for more.
Hope that helps,
Rajiv -
I hope this will save other developers some time.
This may be obvious to others, but I just spent several hours Googling and testing to determine what actually happens when a user copies text containing "Smart Quotes" from Microsoft Word into a Java JTextComponent. For those not familiar with Smart Quotes, by default, MS Word changes double-quoted strings from using the US-ASCII character for quote (0x22) into left- and right- curly quotes (UTF-16: 0x201c and 0x201d). Word also does this with serveral other characters. This plays havoc with the display and Java Strings later encoded with java.beans.XMLEncoder, unless treated carefully. Here is what I discovered (obviously, this applies to MS Windows):
All values are in hexadecimal.
- Word is storing the character for double quote as UTF-16 internally (201C).
- When the character is copied to the clipboard, it is copied as UTF-8 (E2 80 9C).
- When the clipboard is pasted into Java, Java is assuming the it was originally Windows-1252 encoded, because that is the default for the US-EN locale in Windows XP (probably also Vista, but I only tested in XP).
- Java translates this into a-circumflex, euro-sign, o-e-ligature, the characters corresponding to E2, 80, and 9C respectively in Windows-1252 and represents it internally in UTF-16 as 00E2 20AC 0153.
-When the String is XML-encoded using java.beans.XMLEncoder, it is written in UTF-8 as C3A2 E282AC C593, which equates to UTF-16 00E2 20AC 0153 -- the characters a-circumflex, euro-sign, o-e-ligature.
I am not sure how to fix this, but maybe another reader does. I am experimenting with the Clipboard (java.awt.datatransfer) to see if I can programmatically find out the original character encoding (in this case, UTF-16).Doesn't the DataFlavor contain the character encoding? What is the content of the InputStream returned by
InputStream is = (InputStream)contents.getTransferData(DataFlavor.getTextPlainUnicodeFlavor());
If I use
DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor();
String mimeType = df.getMimeType();
String encoding = mimeType.replaceAll(".*?charset=(.*?)\\s*$", "$1");
InputStream is = (InputStream) contents.getTransferData(df);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
for (int count = 0; (count = is.read(buffer)) != -1;)
baos.write(buffer, 0, count);
baos.close();
result = baos.toString(encoding);to transfer
Hello "World"
which Word changes the quotes to the smart 'smart quotes' version I get as a result
Hello World
which is what I expect.
Am I missing something?
Edited by: sabre150 on Sep 4, 2009 1:27 PM -
Problem acessing KM in Web dynpro for upload a file
Hello all.
I have a problem to put a file inside a KM repository. I create a context element like a binary - fileData - and like a String - fileName. and the both code then i will show, I give the same error!!
please try to help me, in where is my error...
Code 1:
public void onActionsavePolitic(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionsavePolitic(ServerEvent)
IPrivatePoliticCreationView.IFilenodeElement fileelement= wdContext.createFilenodeElement();
wdContext.nodeFilenode().bind(fileelement);
IWDAttributeInfo attInfo = wdContext.nodeFilenode().getNodeInfo().getAttribute("fileData");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType =(IWDModifiableBinaryType) wdContext.nodeFilenode().getNodeInfo().getAttribute("fileData").getModifiableSimpleType();
IWDNodeElement element = wdContext.getParentElement();
String filename = element.getAttributeAsText("fileName");
if (filename.trim().equals(""))
return;
try {
/*Get an object of current Portal user */
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
ResourceContext context = new ResourceContext(ep5User);
/*Give the path to KM in the variable path */
String path="/documents/News/";
RID rid = RID.getRID(path);
IResourceFactory factory =
ResourceFactory.getInstance();
ICollection folder = (ICollection) factory.getResource(rid,context);
//Using the upload element we can upload the files to a location in the server drive
/*temperory location for writing */
String location = "d:\";
String fileName = location+ fileelement.getFileName();
File file = new File(fileName);
/*Create an output stream for writing to the temperory location*/
FileOutputStream out = new FileOutputStream(file);
out.write(fileelement.getFileData());
out.close();
/*From the temporary location read the file using an input stream*/
FileInputStream fin = new FileInputStream(fileName);
fin.read();
/*Using this input stream we can write to the repository
Content content = new Content(fileelement.getFiledata(),fileelement.get) */
Content content = new Content(fin,"byte", -1);
IResource newResource = folder.createResource(fileelement.getFileName(),null, content);
fin.close();
file.delete();
} catch (NotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WDUMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WDRuntimeException e) {
wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(""+e.getMessage());
}catch (IllegalArgumentException e) {
wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(""+e.getMessage());
//@@end
Code 2:
public void onActionsavePolitic(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
//@@begin onActionsavePolitic(ServerEvent)
IPrivatePoliticCreationView.IFilenodeElement fileelement= wdContext.createFilenodeElement();
wdContext.nodeFilenode().bind(fileelement);
IWDAttributeInfo attInfo = wdContext.nodeFilenode().getNodeInfo().getAttribute("fileData");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType =(IWDModifiableBinaryType) wdContext.nodeFilenode().getNodeInfo().getAttribute("fileData").getModifiableSimpleType();
IWDNodeElement element = wdContext.getParentElement();
String filename = element.getAttributeAsText("fileName");
if (filename.trim().equals(""))
return;
try {
// Get an object of current Portal user
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
// create an ep5 user from the retrieved user
ResourceContext context = new ResourceContext(ep5User);
// Give the path to KM in the variable path
String repository = "//documents//News//";
RID rid = RID.getRID(repository);
IResourceFactory factory = ResourceFactory.getInstance();
ICollection folder = (ICollection) factory.getResource(rid, context);
byte[] byteArray =
(byte[]) wdContext.currentFilenodeElement().getFileData();
// From the temporary location read the file using an input stream
ByteArrayInputStream fin = new ByteArrayInputStream(byteArray);
// Using this input stream we can write to the repository
Content content =
new Content(fin, binaryType.getMimeType().getHtmlMime(), -1L);
try {
IMutablePropertyMap propertyMap = new MutablePropertyMap();
IResource newResource =
folder.createResource(
wdContext.currentFilenodeElement().getAttributeAsText(
"fileData"),
propertyMap,
content);
} catch (NameAlreadyExistsException re2) {
try {
fin = new ByteArrayInputStream(byteArray);
content =
new Content(
fin,
binaryType.getMimeType().getHtmlMime(),
-1L);
RID fileRid = RID.getRID(repository + filename);
IResource fileResource = factory.getResource(fileRid, context);
fileResource.updateContent(content);
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportSuccess(
"File doesn't exist:" + e.getMessage());
fin.close();
} catch (Exception e) {
wdComponentAPI.getMessageManager().reportException(
"File not found." + e.getMessage(),
true);
} finally {
element.setAttributeValue(wdContext.currentFilenodeElement().getFileName(), null);
//@@end
and the error then I have in same codes is:
java.lang.IllegalArgumentException:
at com.sap.tc.webdynpro.clientserver.data.DataContainer.createLocalPath(DataContainer.java:1347)
at com.sap.tc.webdynpro.clientserver.data.DataContainer.updateAttribute(DataContainer.java:451)
at com.sap.tc.webdynpro.clientserver.uielements.adaptbase.AbstractAdapter.updateAttribute(AbstractAdapter.java:644)
at com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FileUploadAdapter.onFILEUPLOADCHANGE(FileUploadAdapter.java:298)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
com.sap.tc.webdynpro.services.exceptions.WDRuntimeException
at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.handleUIElementEvent(HtmlClient.java:957)
at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.updateEventQueue(HtmlClient.java:372)
at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.prepareTasks(AbstractClient.java:93)
at com.sap.tc.webdynpro.clientserver.session.ApplicationSession.doProcessing(ApplicationSession.java:294)
at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessingStandalone(ClientSession.java:707)
at com.sap.tc.webdynpro.clientserver.session.ClientSession.doApplicationProcessing(ClientSession.java:661)
at com.sap.tc.webdynpro.clientserver.session.ClientSession.doProcessing(ClientSession.java:229)
at com.sap.tc.webdynpro.clientserver.session.RequestManager.doProcessing(RequestManager.java:152)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:62)
at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doPost(DispatcherServlet.java:53)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)
at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)
at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)
at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)
at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)
at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)
at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)
at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)
at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)
at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
at java.security.AccessController.doPrivileged(Native Method)
at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)
at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.sap.tc.webdynpro.clientimpl.html.client.HtmlClient.handleUIElementEvent(HtmlClient.java:949)
... 25 more
Caused by: java.lang.IllegalArgumentException:
at com.sap.tc.webdynpro.clientserver.data.DataContainer.createLocalPath(DataContainer.java:1347)
at com.sap.tc.webdynpro.clientserver.data.DataContainer.updateAttribute(DataContainer.java:451)
at com.sap.tc.webdynpro.clientserver.uielements.adaptbase.AbstractAdapter.updateAttribute(AbstractAdapter.java:644)
at com.sap.tc.webdynpro.clientserver.uielib.standard.uradapter.FileUploadAdapter.onFILEUPLOADCHANGE(FileUploadAdapter.java:298)
... 30 moreHello
It looks that I have a similar problem - how could you solve your problem.
Thanks in advance
Sascha Fuchs
Maybe you are looking for
-
JDBC Lookup - Import table data from a different schema in same DB
Hi XI Experts, We are facing an issue while importing a Database table into the external definition in PI 7.1. The details are as below: I have configured user 'A' in PI communication channel to access the database. But the table that I want to acces
-
Mobility Groups Between...
Hi experts, I am managing 3 WLC: 1- WLC 2112 - code version 7.0.235.0 2- WLC 2112 - code version 7.0.235.0 3- WLC 5508 - code version 7.6.130.0 (new purchase) Is possible to group this 3 WLCs in one Mobility Group
-
How to insert a table data into temporary table
Hi Can anyone help me to insert a table data into temporary table. Thanks Navin
-
How to restore iTunes movie thumbnails?
iTunes has lost the thumbnail images for all my purchased movies. The TV show thumbnails are OK. Only the movie thumbnails have been lost. How can they be restored?
-
Dear All, Recently I purchased a Nokia N8-00, I made backup of my Nokia 3110c (two times only SMS) and E65 (Only SMS) through PC suite and OVI suite. Now I want to restore all SMS to my new Nokia N8-00. Please tell me how to do this from last 3 backu