我正在做一个大学的课程项目,并且负责使配置文件系统正常运行。我们的讲师给了我们一些示例代码,以使文件上传工作正常进行,我将用它来处理用户的个人资料图片,但是,即使我的代码看起来非常相似,我似乎也无法使它正常工作。问题是该文件实际上不会创建并保存在我的项目中,而讲师给我的代码却可以!
这是讲师给我的代码:
NewsStory newsstory = new NewsStory();
newsstory.uniqueid = "story_"+System.currentTimeMillis();
newsstory.dateItWasPublished = System.currentTimeMillis();
newsstory.title = toProcess.params.get("title");
newsstory.description = toProcess.params.get("description");
newsstory.journalists.add(toProcess.params.get("journalist"));
newsstory.filepathToImage = toProcess.params.get("fileupload");
File uploaded = new File(newsstory.filepathToImage);
int ind = newsstory.filepathToImage.lastIndexOf('.');
String extension = newsstory.filepathToImage.substring(ind);
uploaded.renameTo(new File("httpdocs/"+newsstory.uniqueid+extension));
newsstory.filepathToImage = newsstory.uniqueid+extension;
//At this point you would normally add the newsstory to the database
MVMap<String, NewsStory> newsStories = db.s.openMap("NewsStories");
newsStories.put(newsstory.uniqueid, newsstory);
这基本上是从通过表单传入的fileupload参数中获取一个String并运行下面的代码。这是我的代码:
user.userEmail = toProcess.params.get("email");
user.profilePicturePath = toProcess.params.get("filepath");
System.out.println(user.profilePicturePath);
File uploaded = new File(user.profilePicturePath);
int ind = user.profilePicturePath.lastIndexOf('.');
String extension = user.profilePicturePath.substring(ind);
uploaded.renameTo(new File("httpdocs/"+user.username+"ProfilePicture"+extension));
user.profilePicturePath = user.username+"ProfilePicture"+extension;
System.out.println(user.profilePicturePath);
users.put(user.username, user);
db.commit();
有人知道我为什么会遇到这个问题吗?