Following is the curl for a service
Service curl
curl --location --request POST 'https://someapi.com/api/v2/tickets' \
--header 'Authorization: Basic sdsdfsdfsdfsdf=' \
--header 'Cookie: _x_w=5_2' \
--form 'attachments[]=@"/home/Downloads/sample.pdf"' \
--form 'email="example@example.com"'
The following setup works fine with Quarkus 2.12.2-Final, But it uploads the file with the static file name specified in @PartFileName(), my requirement is to upload the file with the dynamic name and content type, can someone please guide me on how can I update this to read the file name with extension dynamically?
Client
@Path("/v2/tickets")
@RegisterRestClient(configKey = "sampleKey")
public interface SampleClient {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
SampleResponse create(
@HeaderParam("Authorization") String authorization,
@MultipartForm MultipartBody data);
}
MultipartBody
public class MultipartBody {
@FormParam("attachments[]")
@PartFilename("sample.pdf")
@PartType(MediaType.APPLICATION_OCTET_STREAM)
public File file;
@FormParam("email")
@PartType(MediaType.TEXT_PLAIN)
public String email = "abcd@bixy.com";
}
Repository
public class SampleRepositoryImpl implements SampleRepository {
@Inject
@RestClient
SampleClient client;
@Override
public SampleResponse create(MultipartBody request) {
MultipartBody body = new MultipartBody();
File f = new File("/home/Downloads/sample.pdf");
body.setFile(f);
return client.create(getAuthHeader(), body);
}
}
Maven dependencies
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-multipart</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-jwt</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-health</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>