Multipart response for web service

Multipart response for web service

By : chitranjan singh
Date : November 25 2020, 07:27 PM
hope this fix your issue I don't know exactly what kind of front end you are using and what your browser compatibility requirements are, or you need the webservice for integration with other apps only, but assuming you are communicating with server over ajax and your app is running in modern browser (or you are allowed to use flash plugin), you can return file contents as base64 encoded string as a part of json response. So in rails controller you would have something like this:
code :

Share : facebook icon twitter icon
Jax-RS Multipart response

Jax-RS Multipart response

By : Riz920
Date : March 29 2020, 07:55 AM
will help you In Jersey you can use jersey-media-multipart module to make your life easier. Follow the documentation on this topic: Multipart section in Jersey User Guide or take a look at the available example multipart-webapp.
Constructing multipart response

Constructing multipart response

By : tdalseide
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Got it. You can also add complete response to a MultipartContent as well.
code :
MultipartContent content = new MultipartContent("mixed", "----Boundary");
content.Add(new HttpMessageContext(response1));
content.Add(new HttpMessageContext(response2));
How to send a multipart file to a service from another service

How to send a multipart file to a service from another service

Date : March 29 2020, 07:55 AM
hope this fix your issue I have two endpoints api which are /uploadand /redirect , This made the trick
code :
@RequestMapping(value = "/redirect", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.POST)
    public ResponseEntity<?> registerBatchUser(@RequestParam("file") MultipartFile file) {
       if (!file.isEmpty()) {
            try {
                byte[] bytes = file.getBytes();
                BufferedOutputStream stream = new BufferedOutputStream(
                        new FileOutputStream(new File("D:\\myfileredirect.csv")));

            } catch (Exception e) {
                JwtAuthenticationErrorResponse FeedBackResponse = new JwtAuthenticationErrorResponse();
                Map<String, Object> FeedBackStatus = new HashMap<String, Object>();
                FeedBackStatus.put("status", FeedBackResponse);
                return ResponseEntity.ok(FeedBackStatus);
        MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>();
        parameters.add("file", new FileSystemResource("D:\\myfileredirect.csv")); 
        HttpHeaders headers = new HttpHeaders();
        headers.set("Content-Type", "multipart/form-data");

        Map<String, Object> FeedBackStatus=new HashMap<String, Object>();
        FeedBackStatus =  restTemplateUserRegitration.exchange("http://localhost:8080/upload",  HttpMethod.POST,  new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class).getBody();
        return ResponseEntity.ok(FeedBackStatus);

How to parse and save a Multipart/related type=image/jpeg response? (Dicom Wado Response)

How to parse and save a Multipart/related type=image/jpeg response? (Dicom Wado Response)

By : user3232723
Date : March 29 2020, 07:55 AM
help you fix your problem I figured out that I was parsing the multi-part response properly, but I had to use another library (library name : imagecodecs , method name : jpegsof3_decode) to decompresses individual part into the images. This is give a numpy array of the image. Here is the updated code
code :
reader = aiohttp.MultipartReader.from_response(response)
while True:
     part = await reader.next()
     if part is None:
     data = await part.read()
     imageDecompressed = jpegsof3_decode(data)
success, encoded_image = cv2.imencode('.png',imageDecompressed)
imageInBytes = encoded_image.tobytes()
How to pass Multipart file from one service to another service in spring boot?

How to pass Multipart file from one service to another service in spring boot?

By : YanYan22
Date : March 29 2020, 07:55 AM
help you fix your problem At last able to solve the communication issue to the another service using the post File upload spring cloud feign client
I have changed the FeignClient parameter type from
code :
@PostMapping(value="/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
        ResponseEntity<Properties> upload(@RequestHeader(name=UID,required=false) String uid, @RequestPart("file") MultiValueMap<String, Object> file);
    public ResponseEntity<Properties> uploadAttachment(@RequestHeader(IRSConsts.UID) String uid, @RequestParam("file") MultipartFile mFile) {
        MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
        ByteArrayResource contentsAsResource = null;
        try {
            contentsAsResource = new ByteArrayResource(mFile.getBytes()) {
                public String getFilename() {
                    return mFile.getOriginalFilename();
        } catch (IOException e) {
        multiValueMap.add("file", contentsAsResource);
        return transSvcClient.upload(uid, multiValueMap);
@PostMapping(path = "/upload")
    @Headers("Content-Type: multipart/form-data")
    public ResponseEntity<Properties> upload(@RequestHeader(name = UID, required = false) String uid,
            @RequestPart("file") MultipartFile multiPart) {
        //Save Attachment.
Related Posts Related Posts :
  • Ruby on Rails - unable to convert "\x89" from ASCII-8BIT to UTF-8 for xxx/xxxx/xxxx
  • In Ruby on Rails, After send_file method delete the file from server
  • An error occurred while installing nokogiri (, and Bundler cannot continue
  • How to setup nested routing for a self referencing controller in Rails 4
  • middleman app it is possible to create a contact form?
  • How to refactor this piece of code
  • How can I know if a user has access to all or just some resources with Cancan?
  • How can I run a ruby class from rake file?
  • Send JSON data as post method from rails controller to a web service
  • How to test Controllers under different namespaces and why this test fails?
  • rspec expect condition OR condition
  • Page loads unnecessary queries Ruby On Rails
  • Why "bundle install" try to install outdated version of gems?
  • Rails - Customize model validation error messages but without a database
  • When to switch from cucumber to rspec in the BDD cycle for a login procedure
  • How to hide Add new option in Rails Admin
  • Override CollectionProxy find method
  • Rails 4 simple_form has_many through check boxes not saving
  • ruby on rails authentication using devise gem
  • Rails iteration over arrays and hashes
  • Creating inline date_select dropdowns using simple_form and zurb foundation
  • NameError in SongsController#index uninitialized constant Song::FriendlyId
  • Rails how to improve if record exists?
  • omniauth custom request phase form
  • Rails 5 - Saving the absolute current url via a button to a cookie?
  • How can / should I override the `build` method for a my model?
  • Install Rails Failed on OSX 10.8.4
  • ruby on rails - undefined method valid?
  • Users Registration on POST
  • Rails application variables in carrierwave store_dir
  • How to customize simple_form for json nested hash
  • Couldn't find file 'jquery', Sprockets::FileNotFound in StaticPages#home error
  • How should I use the alias_method_chain for the build method?
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org