Can I upload an image into a blob by the Servoy Headless Client?
Does anyone have some sample-code?
It is rather urgent!
HJK wrote:Robert, it is for the headless client!
<form action="myImageUploadPage.jsp" method="post" enctype="multipart/form-data">
Image 1: <input type="file" name="file1" value="">
</form>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Upload Test</title>
</head>
<body>
<form action="upload.jsp" name="upform" enctype="multipart/form-data" method="post">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<td align="left">
<b>Select a file to upload :</b>
</td>
</tr>
<tr>
<td align="left">
<input type="file" name="fileName" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload"> <input type="submit" name="Submit" value="Upload"> <input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page import = "java.io.*" %>
<%@ page import = "java.util.*" %>
<%
String path=request.getParameter("fileName");
String newPath="";
int count=0;
if(path!=null)
{
ArrayList arr=new ArrayList();
StringTokenizer st=new StringTokenizer(path,"\\");
while(st.hasMoreTokens())
{
arr.add(count,st.nextToken());
count++;
}
// create ur own path
newPath="/Users/robert"+arr.get(count-1);
int c;
FileInputStream fis=new FileInputStream(path);
FileOutputStream fos=new FileOutputStream(newPath);
while((c=fis.read())!=-1)
{
fos.write((char)c);
}
}
out.println("Thanks for using");
out.println("<br>");
out.println("<br>");
out.println("1.File1 Uploaded from :: "+path);
out.println("<br>");
out.println("<br>");
out.println("2.Uploaded File1 is Saved in :: "+newPath);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>file upload</title>
</head>
<body>
<form action="upload.jsp" name="upform" enctype="multipart/form-data" method="post">
<table width="60%" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td align="left">
<b>Select a file to upload :</b>
</td>
</tr>
<tr>
<td align="left">
<input type="file" name="fileName" size="50">
</td>
</tr>
<tr>
<td align="left">
<input type="hidden" name="todo" value="upload"> <input type="submit" name="Submit" value="Upload"> <input type="reset" name="Reset" value="Cancel">
</td>
</tr>
</table>
</form>
</body>
</html>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="org.apache.commons.fileupload.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.File" %>
<%
try {
FileUpload fup=new FileUpload();
boolean isMultipart = FileUpload.isMultipartContent(request);
// Create a new file upload handler
DiskFileUpload upload = new DiskFileUpload();
// Parse the request
List items = upload.parseRequest(request);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (!item.isFormField()) {
File cfile = new File(item.getName());
// Path relative to <servoy>/server/webapps/ROOT/
// In this case the subdirectory "upload"
// Make sure the directory exists
File tosave = new File(getServletContext().getRealPath("/") +
"upload/",cfile.getName());
item.write(tosave);
}
}
out.println("<p>Done! Thank you for flying with us ;-)</p>");
// now from here you can tell your Servoy solution where to find the file and fetch it from the HD.
} catch (Exception e){
out.println("<p>Error: " + e + "</p>");
}
%>
Return to Servoy Headless Client
Users browsing this forum: No registered users and 8 guests