954,604 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

photo upload problem

this is a page of code on a Apache Tomcat server
the error i get is the following :

Eror :licenta\upload\Tulips.jpg (The system cannot find the path specified)

project path is :
ROOT\licenta

<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="org.apache.commons.fileupload.FileItemIterator"%>
<%@ page import="org.apache.commons.fileupload.FileItemStream"%>
<%@ page import="org.apache.commons.fileupload.util.Streams"%>
<html>
	<head>
	</head> 
	<body>
		<form action="file_up.jsp" enctype="multipart/form-data" method="post">
			 What is your name? <INPUT type="text" name="submit-name"><BR>
			What files are you sending? <input type="file" name="file">
			<input name="submit" type="submit" value="Upload photo">
			<INPUT type="reset">
		</form>
		<%
		String result = null;
		try {
			if(ServletFileUpload.isMultipartContent(request)){
			
				DiskFileItemFactory factory = new DiskFileItemFactory();

				ServletFileUpload upload = new ServletFileUpload(factory);
				
				upload.setSizeMax(-1);
				
				List items = upload.parseRequest(request);
				
				Iterator iter = items.iterator();
				
				while (iter.hasNext()) {
					FileItem item = (FileItem) iter.next();
					if (!item.isFormField()) {
						String fileName = item.getName();
						String contentType = item.getContentType();
						boolean isInMemory = item.isInMemory();
						long sizeInBytes = item.getSize();
						File fup = new File("licenta/upload/"+fileName);
						item.write(fup);
					}else{
						String name = item.getFieldName();
						String value = item.getString();
					}
				} 
			}
		}
		catch(Exception ex){
			result = "Eror :" + ex.getMessage();
		}
		out.println(result);
		%>
	</body>
</html>
bowmaster
Newbie Poster
14 posts since Aug 2010
Reputation Points: 7
Solved Threads: 0
 

As error says, file cannot be found as you are providing relative path. You should have provided absolute path

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

can you give me an example?
in the documentation it says that a absolute path is one with / at the front
and i tried that too and got the same error.
i am working on Windows operating system but the server is apache tomcat
if it makes any difference
thank you for your time

bowmaster
Newbie Poster
14 posts since Aug 2010
Reputation Points: 7
Solved Threads: 0
 

If you working on Windows then absolute path would be drive letter with directions to file, example C:\Images\img01.jpeg

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

C:\Program Files (x86)\Apache Software Foundation\Tomcat 7.0\webapps\examples\images\
i pasted that from explorer
and got this error

An error occurred at line: 44 in the jsp file: /licenta/file_up.jsp
Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ )

bowmaster
Newbie Poster
14 posts since Aug 2010
Reputation Points: 7
Solved Threads: 0
 

i replaced \ with \\ and it worked thank you very much
will try next to save in project folder

bowmaster
Newbie Poster
14 posts since Aug 2010
Reputation Points: 7
Solved Threads: 0
 

again thank you very much

bowmaster
Newbie Poster
14 posts since Aug 2010
Reputation Points: 7
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: