通过网络发送时,spring是否对二进制数据进行编码?

时间:2018-11-24 08:47:30

标签: java json spring binary

我正在使用Spring Boot创建REST API,并计划同时进行客户端(移动)方面的工作。我想知道什么是返回和接收文件(图像等)的最佳方法,因为当我返回带有二进制数组作为字段的对象时:

@GetMapping("/downloadProfile/{fileId}")
        public Profile downloadProfile(@PathVariable String fileId) {
            Profile profile = profileService.findById(Long.parseLong(fileId));

            return profile;
        }

....

@Entity
@Table(name = "profiles")
public class Profile {

    @Id
    @GeneratedValue
    private Long id;

    private String firstName;

    private String lastName;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "image_id")
    private Image image;

    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "location_id")
    private Location location;
    ...

我得到JSON:

{
    "id": 1,
    "firstName": "May",
    "lastName": "Clark",
    "image": {
        "fileName": "dog.jpg",
        "fileType": "image/jpeg",
        "data": "/9j/4AAAQsk ...

它是自动在Base64中编码还是只是二进制数据?如果是,我是否应该以编码格式将其存储在DB中?在客户端上发送简单工作的正确方法是什么?

0 个答案:

没有答案