Fórumok

Problem in FileUpload

shrikanth shrikanth, módosítva 9 év-val korábban

Problem in FileUpload

Regular Member Bejegyzések: 118 Csatlakozás dátuma: 2013.12.11. Legújabb bejegyzések
Hello frds.......................

Iam fasing one major issue in Liferay.iam doing one portlet...........in tht iam uploading a file @created location ..... and send file name to database.and i want to download the file.................

the Problem iam get is........
iam successfully inserting a file in a folder and sending a name to datasbases also......but @ retrive time iam getting 404 error File Not found....but the file is inserting properly.......and when iam restarting a server na on tht time its retriving properly.......if again iam adding naaa its showing 404 error in unbatu machine......i think its going @Temp folder for Searching a File..........soooo how to clean on Temp file on submit......
in UNIX machine iam getting 404 error only,,,,, in windows its working properly.in windows its searching in temp file and file iam stroing in ............created location only

plz see my java code for file upload

String fileinput = null;
List<String> filename_db = new ArrayList<String>();
String tendernumber = new String();
String tenderdescription = new String();
String tenderdate = new String();
int tenderdesId = 0 ;
FileItemFactory factory = new DiskFileItemFactory();
System.out.println("FileItemFactory......." + factory);
ServletFileUpload upload = new ServletFileUpload(factory);
System.out.println("servletFileUpload...." + upload);
java.util.Properties properties = PortalUtil.getPortalProperties();
System.out.println("my properties is...." + properties);
File directory = new File(properties.getProperty("liferay.home")
+ "/tomcat-7.0.42/webapps/File-portlet/file");
if (!directory.exists()) {
directory.mkdir();
System.out.println("type directory exists");
}
HttpServletRequest httpServletRequest = PortalUtil
.getHttpServletRequest(actionRequest);
try {
List fields = upload.parseRequest(httpServletRequest);
Iterator<FileItem> it = fields.iterator();
while (it.hasNext()) {

FileItem fileItem = it.next();
String portlet_id = "_File_WAR_Fileportlet_";
if (fileItem.isFormField()) {
if (fileItem.getFieldName().equals(
portlet_id + "name")) {
name = fileItem.getString();
}

}
if (!fileItem.isFormField()) {
String FileName = fileItem.getName();
File file = new File(directory, FileName);
try {
if (!file.exists()) {
fileItem.write(file);

}
} catch (Exception e) {
e.printStackTrace();
}



plz check out my code and tellll were iam getting wrong bcoz...........when iam downloading its trowing 404 Error bcoz...its looking the file @ Temp folder and its should look @created location...

Plz help meeeee ....and send feedback as soon as possible

Regards
Shrikanth
thumbnail
David H Nebinger, módosítva 9 év-val korábban

RE: Problem in FileUpload

Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Okay, just got done going through this in another thread.

You cannot save files into your web app directory. It is against the whole servlet specification. Note that this is a violation of both the portlet and servlet spec, so don't do it.

For example, if you push a new WAR the container will typically delete your webapp directory, then re-expand back in it's place. Or perhaps you're using unexploded wars, in which case you don't have a directory at all.

Besides, this will fail in a cluster also.

The only real way to do this is to use the document library. Appendix E of Liferay in Action.