Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

image can't handled by spring boot REST framework on external tomcat on POST method. Return 404 erro

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am working with the following environment. 1. IDE eclipse mars(4.5.2) 2. Gradle 3. Spring boot (tomcat is embedded) 4. Angular Js with grunt.

Problem : I want to upload image on AWS S3. When I ran on locally with embedded tomcat with "spring bootrun" command and upload the file from bowser /Postman API call, the image uploaded fine.

But when I make war file by gradle war command and run it inside tomcat 7 or tomcat 8 and go for same task, the rest controller of spring boot framework could not find the image file.

Please help me to overcome this strange issue.

File information :

@RestController
@RequestMapping("/profilePicture")
public class ProfileImageUploadController extends BaseController {

   @Autowired
   private ImageStoreOnAws imageStoreOnAws;

   @RequestMapping(value = "/upload", method = RequestMethod.POST)
   public ResponseEntity<Map<String, Object>> getPictureUploadUrl(@AuthenticationPrincipal OttaAccountDetails principal, MultipartHttpServletRequest request) {
       Map<String, Object> response = new HashMap<>();
       System.err.println("REQUEST---------------->"+request.getContentLength());
       System.err.println("\nagain info---------------->"+request.getRequestURI());
       MultipartFile multiFile = request.getFile("profile_pic");
       System.err.println("Multipart file --------->"+multiFile);
       System.err.println("\n Content Type --------->"+request.getContentType());

       //String pictureUploadUrl = displayPictureImageStore.uploadUrl("/session/picture/" + principal.getUserId(), 10485760);
       response = imageStoreOnAws.uploadProfilePicture(principal.getUserId(), multiFile);
       return new ResponseEntity(response, HttpStatus.OK);
   }

Postman API call : http://localhost:8080/profilePicture/upload (it works fine locally. But when I ran inside tomcat with war it does not work locally)

Gradle file (Portion of code) :

apply plugin: 'war'
   war {
       baseName = 'otta-web'
       version = '1.0-SNAPSHOT'
   }
   version = '1.0-SNAPSHOT'

   bootRepackage.enabled = false;
   bootRun.enabled = true;

Output : The print gives the following output.

   REQUEST---------------->1818 again info---------------->/profilePicture/upload Multipart file --------->null Content Type --------->multipart/form-data; boundary=--------------------------182405819892384390851841

The exact output should be like below :

   REQUEST---------------->1818

   again info---------------->/profilePicture/upload Multipart file --------->org.springframework.web.multipart.support.StandardMultipartHttpServletRequest$StandardMultipartFile@181b1cf4

   Content Type --------->multipart/form-data; boundary=--------------------------341504561441584510876671

 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the rest controller of spring boot framework could not find the image file.

Why do you think it can't find the image file?
A reply status of 404 to me indicates it could not find the service. Are you sure it is finding the controller service?

Bill
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic