简体   繁体   English

如何在Play框架下指定其他附件路径

[英]How can i specify a different attachments path under play framework

I'm using play framework now, i already know we can specify the attachments path in application.conf: 我现在正在使用播放框架,我已经知道我们可以在application.conf中指定附件路径:

# Store path for Blob content
attachments.path=data/attachments

My application have different kinds of pictures, i need to separate those pictures into different directories. 我的应用程序具有不同类型的图片,我需要将这些图片分成不同的目录。

How can i implement my thought ? 我该如何实现我的想法?

Many thanks! 非常感谢!

This is my controller code: 这是我的控制器代码:

public static void uploadAvatar(Blob file){
    if(request.isNew){
        Long userId = Long.parseLong(session.get(Constants.USER_ID_IN_SESSION));
        User user = User.findById(userId);
        // Delete old picture
        if (user.avatar.getFile() != null) {
            user.avatar.getFile().delete();
        }
        user.avatar = file;
        user.avatarFileName = file.getFile().getName();
        user.save();
    }
    Users.settings();
}

I would make a class which extends the current blob.class (http://www.playframework.org/documentation/api/1.2.4/play/db/jpa/Blob.html), and reimplement the getStore() method to read a different property than attachments.path (ie avatar.path). 我将创建一个扩展当前blob.class(http://www.playframework.org/documentation/api/1.2.4/play/db/jpa/Blob.html)的类,然后将getStore()方法重新实现为读取与attachments.path(即avatar.path)不同的属性。

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM