Не могу опубликовать фото с помощью jax rs api в весенней загрузке - PullRequest
0 голосов
/ 14 апреля 2020

Ниже приведен код из класса контроллера. Это метод из класса контроллера, который имеет 2 метода для публикации фотографии и получения фотографии. Невозможно сделать сопоставление с этим методом, он использует ajax вызов API. Я думаю, проблема в ajax API, который не может сопоставить с этим методом, я не уверен, что здесь не так

    @Path("/{id}/photo")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
       public Response updatePhoto(@PathParam("id") String id, @FormDataParam("photo") InputStream is) throws RecordNotFoundException {


            boolean updated = sanService.updatePhoto(id, is);
            if (updated)
                return Response.status(Status.OK).entity("").build();
            else
                return Response.status(Status.NOT_MODIFIED).entity("").build();
        }


    @GET
    @Path("/{id}/photo")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response getPhoto(@PathParam("id") String id) {
        String result = sanService.getPhoto(id);

        if (result == null)
            return Response.status(Status.NOT_FOUND).entity("").build();
        else {
            File file = new File(result);
            ResponseBuilder response = Response.status(Status.OK).entity((Object) file);
            response.header("Content-Disposition", "attachment; filename=" + id + ".png");
            return response.build();
        }

    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Response uploadFile(
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String uploadedFileLocation = "C://"
                + fileDetail.getFileName();


        writeToFile(uploadedInputStream, uploadedFileLocation);

        String output = "File uploaded to : " + uploadedFileLocation;

        return Response.status(200).entity(output).build();

    }


    private void writeToFile(InputStream uploadedInputStream,
            String uploadedFileLocation) {

        try {
            OutputStream out = new FileOutputStream(new File(
                    uploadedFileLocation));
            int read = 0;
            byte[] bytes = new byte[1024];

            out = new FileOutputStream(new File(uploadedFileLocation));
            while ((read = uploadedInputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.flush();
            out.close();
        } catch (IOException e) {

            e.printStackTrace();
        }

    }

Ниже это ошибка, которую я получаю в почтальоне, когда выбираю путь для публикации фотографии

{
  "timestamp": "2020-04-03T17:10:10.105+0000",
  "status": 404,
  "error": "Not Found",
  "message": "No message available",
  "path": "/5cedvcb6rfsss5ff300eb/photo"
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...