<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: Streaming with Ivy REST API</title><link>https://answers.axonivy.com/questions/3602/streaming-with-ivy-rest-api</link><description>&lt;p&gt;Dear Ivy Team&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Problem: Currently I am trying to pass binary data -&amp;gt; "In Inscribe Rest Service Call Activity" -&amp;gt; Body, entity -&amp;gt; binary data and content-type=application/octet-stream and read it by the consumer REST service with HttpServletRequest request-&amp;gt;getInputStream(). Though here I get an error (InputStream seems to be already closed).&lt;/p&gt;
&lt;p&gt;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).&lt;/p&gt;
&lt;p&gt;Thanks in advance for a feedback.&lt;/p&gt;
&lt;p&gt;Best Regards
John&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/3602/streaming-with-ivy-rest-api" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 14 Jan 2019 03:39:47 -0500</lastBuildDate><item><title>Answer by Alex Suter</title><link>https://answers.axonivy.com/questions/3602/streaming-with-ivy-rest-api/3609</link><description>&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;But you should can use the plain java api:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;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();
    }
}
&lt;/code&gt;&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Alex Suter</dc:creator><pubDate>Mon, 14 Jan 2019 03:39:47 -0500</pubDate><guid>https://answers.axonivy.com/questions/3602/streaming-with-ivy-rest-api/3609</guid></item><item><title>Answer by Christian Strebel</title><link>https://answers.axonivy.com/questions/3602/streaming-with-ivy-rest-api/3604</link><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;I am not sure if it only works with &lt;strong&gt;multi part form data&lt;/strong&gt; but with it it should work.
Here an example rest service:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@Path("stream")
public class RenewLicenseService
{
  @POST
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.MULTIPART_FORM_DATA)
  public Result upload(@FormDataParam("bigFile") InputStream bigFile)
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Have a nice day&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Christian Strebel</dc:creator><pubDate>Tue, 08 Jan 2019 10:35:40 -0500</pubDate><guid>https://answers.axonivy.com/questions/3602/streaming-with-ivy-rest-api/3604</guid></item></channel></rss>