java - 存储个人资料图片的图像文件的问题
问题描述
我正在为大学做一个课程项目,我负责让配置文件系统正常运行。我们的讲师给了我们一些示例代码来让文件上传工作,我将使用它来制作用户的个人资料图片,但是即使我的代码看起来非常相似,我似乎无法让它工作。问题是该文件实际上不会在我的项目中创建和保存,但我的讲师给我的代码却可以!
这是讲师给我的代码:
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);
这基本上从通过表单传入的文件上传参数中获取一个字符串并运行下面的代码。这是我的代码:
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();
有谁知道为什么我可能会遇到这个问题?
解决方案
推荐阅读
- javascript - 如何使用Javascript有条件地查找顶级父元素
- vba - 使用 VBA 在 power point 幻灯片中的同一对象上单击 2 次之间经过的时间
- c++ - 仅在函数的模板实例化时关联模板成员变量
- javascript - Firefox 问题:在 iframe 加载事件中注入脚本标记时过早触发?
- c# - ASP.NET Core 2.1,Angular 5:Hangfire Auth 仅适用于登录
- python - 如何在 pandas 数据框中选择特定值并将其替换为 NaN。如何从每个级别 1 多索引中删除一列
- .htaccess - htaccess 操作查询字符串
- mesos - 为什么 Marathon 调度程序在重启 marathon 服务时会重启部署?
- neo4j - Neo4j:如何从 mac 中卸载 Neo4j?
- r - dplyr 后的列引用不起作用