保誠-保戶業務員媒合平台
Jack
2021-11-14 97e093b1117b68948d0f9adefacc5368014db380
pamapi/src/main/java/com/pollex/pam/web/rest/ConsultantResource.java
@@ -2,10 +2,17 @@
import com.pollex.pam.service.ConsultantService;
import com.pollex.pam.service.dto.*;
import org.apache.commons.compress.utils.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@RestController
@@ -59,4 +66,14 @@
       return consultantService.getMyAppointment();
    }
    
    @GetMapping(value = "/avatar/{fileName}", produces = MediaType.IMAGE_JPEG_VALUE)
    public ResponseEntity<byte[]> getAvatarImage(@PathVariable String fileName) throws IOException {
        try {
            Resource resource = new ClassPathResource("static/consultant/" + fileName);
            InputStream in = resource.getInputStream();
            return new ResponseEntity<>(IOUtils.toByteArray(in), HttpStatus.OK);
        } catch (FileNotFoundException e) {
            return new ResponseEntity<>(HttpStatus.NOT_FOUND);
        }
    }
}