0

I am using sts to write my code and here is the problem now when I try to post the photo/attachments I am receiving the error 404 in postman and whitelabel error in browser

Below is the code snippet from controller class, for photo attachment

@POST
@Path("/{id}/photo")
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();
}

This is the variable from model class

@Id
private String id;
private String attachments;

Below is the error i am receiving in postman when i am hitting the path to post the photo

{
  "timestamp": "2020-04-03T17:10:10.105+0000",
  "status": 404,
  "error": "Not Found",
  "message": "No message available",
  "path": "/upload"
}

This is the url i am hitting to post the attachment in postman as well as in browser

http://localhost:8082/5e845cea6cdb4531f30023ab/photo

Please assist or advice how can I proceed

  • What is the path to the controller? – npinti Apr 03 '20 at 09:13
  • projectname/src/controller package/controller class – SAN SHADES Apr 03 '20 at 09:37
  • What I meant was something similar the question in [this](https://stackoverflow.com/questions/28006501/how-to-specify-prefix-for-all-controllers-in-spring-boot) post. Notice the `@RequestMapping("/users")` on top of the controller. It might be that in your case either that is missing from the setup of the controller or else, it is missing in the URL you are trying to hit. – npinti Apr 03 '20 at 09:41
  • /sourcing/src/main/java/com/san/controller/SANcontroller.java this is the controller path – SAN SHADES Apr 03 '20 at 10:27
  • no I did not used @requestmapping annotation – SAN SHADES Apr 03 '20 at 10:59

1 Answers1

0
  1. Please make sure you have your controller class annotated correctly with @RestController annotation.

  2. Please check if you have annotated your controller class with something like @RequestMapping("/foo"). In that case you need to define this request path: /foo/{id}/photo

  3. Your controller method can be annotations can be written a bit cleaner. Instead of those two annotations you can use this: @PostMapping("/{id}/photo")

GoranLegenda
  • 491
  • 3
  • 9
  • yeah I have checked all this step...but still the issue is the same – SAN SHADES Apr 03 '20 at 10:58
  • Are you maybe setting context-path in your yaml configuration? If you are, that needs to prefixed as well to your path – GoranLegenda Apr 03 '20 at 11:10
  • Hi GoranLegenda, please find the yaml content below server.port=8082 spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=sanservice spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration spring.main.allow-bean-definition-overriding=true spring.mail.host=smtp.gmail.com spring.mail.port=587 spring.mail.username= san@gmail.com spring.mail.password= san spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true – SAN SHADES Apr 13 '20 at 13:19