2

I'm working on a application in which users can update their information. For the moment, RFC 6902 Json-patch is used to update textual information (firstname, lastname, phone...) via a basic HTML Form.

User can now add images to their profile. Is there any way to use Json-patch to perform multipart operations ?


Note : The images are stored in a file system. So in the client side, only the image path is given and it can be updated only after the form submission. My dto is as below :

public class ProfileDto {

    private Integer id;

    private String firstname;

    private String lastname;

    private String defaultMedia; // <-- image path
    ...
}

Solution to which I think :

Since defaultMedia is of type String, Json-patch can be used to update the image path. The idea is when the form is submitted, perform a Multipart POST request to upload the image and get its URL. Then set defaultMedia of my DTO to the new URL.

This solution can create unsued images in the case when a error happened server side on form submission. So I need to add something to clean the file system.

Is there any easier solution to meet my needs ?


I'm using :

  • Spring Boot : 1.5.1
  • Angular 2 : 2.4.5
Radouane ROUFID
  • 10,595
  • 9
  • 42
  • 80

0 Answers0