Dear Ivy Team

I have the following case: User should be able to upload scanned documents (1...xx MB) via Ivy and the data should be streamed through the REST service (layers). Since each REST service decouples (therefore no shared memory) the memory required to transport the document data could be quite high. To avoid that I would like to stream the data down to the persistency layer.

Problem: Currently I am trying to pass binary data -> "In Inscribe Rest Service Call Activity" -> Body, entity -> binary data and content-type=application/octet-stream and read it by the consumer REST service with HttpServletRequest request->getInputStream(). Though here I get an error (InputStream seems to be already closed).

Question: Is this approach correct or do I have to use multipart/form-data (if yes, do you have an example, especially if the call is executed by the Ivy REST client).

Thanks in advance for a feedback.

Best Regards John

asked 08.01.2019 at 10:00

John%20Moser's gravatar image

John Moser
(suspended)
accept rate: 0%


Hello It is not possible to send files with the Rest Client Activity. You have to use the Java API. There is story planned to support this feature.

But you should can use the plain java api:

package ch.ivy;

import java.io.File;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
import org.glassfish.jersey.filter.LoggingFilter;
import org.glassfish.jersey.media.multipart.MultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;

import com.fasterxml.jackson.databind.JsonNode;

public class Slimclient {
    private static final String TARGET_URL = "http://185.19.29.20:8082/alfresco/api/-default-/public/alfresco/versions/1/nodes/311aac82-d9bc-4da3-9337-0069571d321a/children";

    public Slimclient() {

        HttpAuthenticationFeature autfeature = HttpAuthenticationFeature.basic("admin", "admin");

        Client client = ClientBuilder.newBuilder()
                .register(new LoggingFilter())
            .register(MultiPartFeature.class).build();
        client.register(autfeature);


        Response get = client.target(TARGET_URL).request().get();
        System.out.println(get.getStatus());

        WebTarget webTarget = client.target(TARGET_URL);

        MultiPart multiPart = new MultiPart();
        multiPart.setMediaType(MediaType.MULTIPART_FORM_DATA_TYPE);

        FileDataBodyPart fileDataBodyPart = new FileDataBodyPart("filedata",
            new File("C:\\temp\\Banner2.png"),
            MediaType.APPLICATION_OCTET_STREAM_TYPE);
        multiPart.bodyPart(fileDataBodyPart);

        Response response = webTarget.request(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.entity(multiPart, multiPart.getMediaType()));

        System.out.println(response.getStatus() + " "
            + response.getStatusInfo() + " " + response);

        System.out.println(response.readEntity(JsonNode.class));
    }

    public static void main(String[] args) {
        new Slimclient();
    }
}
link

answered 14.01.2019 at 03:39

Alex%20Suter's gravatar image

Alex Suter ♦♦
3.1k122247
accept rate: 84%

Thank you !

(15.01.2019 at 10:17) John Moser John%20Moser's gravatar image

Hi

I am not sure if it only works with multi part form data but with it it should work. Here an example rest service:

@Path("stream")
public class RenewLicenseService
{
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Result upload(@FormDataParam("bigFile") InputStream bigFile)
}

Have a nice day

link

answered 08.01.2019 at 10:35

Christian%20Strebel's gravatar image

Christian St... ♦
3.2k31338
accept rate: 88%

Hi Christian

Thanks - but the issue is the REST client of Ivy. In order to post with MediaType.MULTIPART_FORM_DATA, which type of body has to be used -> "raw" or "form" or "entity" ?

I assume : raw=write your own html form, form=I can't set to be multipart, entity=I can't set a form param

Regards John

(08.01.2019 at 10:51) John Moser John%20Moser's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×37
×33

Asked: 08.01.2019 at 10:00

Seen: 2,071 times

Last updated: 15.01.2019 at 10:17