Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestClient: Uploading Excel Files created with Apache POI #212

Open
HeavyTobi opened this issue Sep 18, 2019 · 6 comments
Open

RestClient: Uploading Excel Files created with Apache POI #212

HeavyTobi opened this issue Sep 18, 2019 · 6 comments

Comments

@HeavyTobi
Copy link

Hello,

At our company we need to upload an excel file created using Apache POI.
I didn't find any possibility to do this.

I already tried using MultipartForm and the Workbook itself, both didn't work.

Used implementation of Rest Client: REST Easy integrated to Quarkus

Is it even possible to upload any files using the REST client? Didn't find any examples on google / stack overflow / github. If it is not possible: This is a feature request.

@rdebusscher
Copy link
Member

You can upload a file (any binary data) using a regular REST endpoint, for example, https://javatutorial.net/java-file-upload-rest-service.

MicroProfile Rest client has nothing to do with defining REST endpoints but calling them. The Quarkus repository/Forum would be a better place to ask this question.

@HeavyTobi
Copy link
Author

You can upload a file (any binary data) using a regular REST endpoint, for example, https://javatutorial.net/java-file-upload-rest-service.

MicroProfile Rest client has nothing to do with defining REST endpoints but calling them. The Quarkus repository/Forum would be a better place to ask this question.

I think you misunderstood my question: I want to upload a file from the java service to another service, not upload a file to the java service

@andymc12
Copy link
Contributor

It is likely possible if you were to use a custom MessageBodyWriter to convert the File object (or whatever the parameter is) to the message body output stream. This is probably the only portable solution as most vendors have their own unique multipart implementation.

I agree that this would be a good feature to have in the MP Rest Client spec. In general, we try to "piggy-back" off of JAX-RS (now Jakarta REST) for consistency. JAX-RS also does not have a spec-defined multipart API, but that has been proposed for the next release. Ideally, whatever we do in MP Rest Client would be compatible with JAX-RS.

@watermelonjam
Copy link

While it would be nice to have an implementation-neutral way of doing this as part of the spec, the current release of Quarkus, 1.7.0.Final, with a dependency on resteasy-client 4.5.6.Final, handles this just fine for me in the case of passing binary file data over to SharePoint via its REST API. Using an InputStream body parameter on the MP REST interface automatically caused it to use its InputStreamProvider for marshalling:

package com.example.sharepoint.rest;

import java.io.InputStream;

import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;

@RegisterRestClient(configKey = "sharepoint-api")
public interface MicroprofileRestClient {
	@POST
	@Path("/web/GetFolderByServerRelativeUrl('{serverRelativeUrl}')/Files/add(url='{fileName}',overwrite=true)")
	@Produces("application/json;odata=verbose")
	@Consumes(MediaType.APPLICATION_OCTET_STREAM)
	Response store(@HeaderParam("Authorization") String authorization,
			@PathParam("serverRelativeUrl") String serverRelativeUrl, @PathParam("fileName") String fileName,
			InputStream content);
}

@jclingan jclingan added this to the 3.1 milestone Feb 26, 2024
@jamezp
Copy link
Contributor

jamezp commented Feb 26, 2024

This should be solved in 3.1 with the upgrade to Jakarta REST 3.1. There was a jakarta.ws.rs.core.EntityPart introduced in Jakarta REST 3.1.

@Emily-Jiang
Copy link
Member

similar situation to #261

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants