Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

fileUpload: destination error

Status
Not open for further replies.

aarushi2001

Technical User
Nov 16, 2005
109
0
0
US
Hi,

I want users to upload file. The files uploaded by them shud be stored under test folder on server (I have created the folder and set required permissions). I am stuck here:

to save file to a particulat location, code is something like:
saveFile = "../webapps/ROOT/download/" + saveFile;
this works well on my local machine.
Same thing I want it to work when online so code should be:
saveFile = " + saveFile;
but this isnt working.. can someone please help me.. its urgent :(
 
Hi

Try some thing like this, which will retruns the path of the download dir.

Code:
String saveFile = this.getServletConfig().getServletContext().getRealPath("/download/").toStirng();

Hope this will help you.

Cheers
Venu

 
Thanks Venu.. but am not using servlet :(

I just have a simple upload.jsp file.. the code is something like this:

Code:
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>

<html><head><script type="text/javascript">
history.go(1);
</script></head></html>

<!-- upload.jsp -->
<%
String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();

byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while (totalBytesRead < formDataLength) {
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}

String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename=\"") + 10);
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
//out.print("FileName:" + saveFile.toString());
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename=\"");

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;

pos = file.indexOf("\n", pos) + 1;


int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
saveFile = "[URL unfurl="true"]http://something.com/download"[/URL] + saveFile;
FileOutputStream fileOut = new FileOutputStream(saveFile);

//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();

}
%>

thanks
 
You can't just write to a URL using a FileOutputStream ...

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
umm.. but then how come this code was working when I was working on my local machine and it worked when I used it for uploading files within the company..

what should I do then? do I need to download uploadFile or something like that?
 
umm.. but then how come this code was working when I was working on my local machine and it worked when I used it for uploading files within the company..

Fine, if you think you can - then good luck !!!
See you when you realise that you cannot ?

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Hey Sedj and Venur,

Morning.. thanks for your help.. it worked..

Sedj: am sorry but I was just trying to ask questions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top