How to Use FileUpload with Quarkus RestClient for Multipart File Uploads
Автор: vlogommentary
Загружено: 2025-12-16
Просмотров: 0
Описание:
Learn how to send multipart file uploads using Quarkus RestClient by converting server-side FileUpload instances into client requests efficiently.
---
This video is based on the question https://stackoverflow.com/q/79512397/ asked by the user 'Cristiano' ( https://stackoverflow.com/u/416104/ ) and on the answer https://stackoverflow.com/a/79514064/ provided by the user 'geoand' ( https://stackoverflow.com/u/2504224/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: How can I use FileUpload in a Quarkus RestClient to upload file to a external rest service?
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to drop me a comment under this video.
---
Introduction
In Quarkus, handling file uploads on the server side is straightforward using org.jboss.resteasy.reactive.multipart.FileUpload. However, sending files from a Quarkus RestClient to an external REST service requires a different approach, especially for multipart requests.
This post explains how to build multipart form requests in Quarkus RestClient by leveraging FileUpload instances received on the server, addressing common confusions about handling multipart data on the client side.
The Problem
You receive multipart file data in a server endpoint using FileUpload.
You need to send these files to an external REST API using a Quarkus RestClient.
The challenge: classes like DefaultFileUpload need non-public implementations and are not straightforward for client-side usage.
Solution Overview: Using ClientMultipartForm to Create Client Requests
Instead of trying to reuse server-side multipart classes directly, the recommended approach is:
Define your server request POJO to map multipart data.
Create a ClientMultipartForm for the client-side request.
Transfer file uploads and form attributes from the server request to the client form.
Example Server Request Class
[[See Video to Reveal this Text or Code Snippet]]
Building the Client Multipart Form
[[See Video to Reveal this Text or Code Snippet]]
Explanation
ClientMultipartForm.create() initializes a new multipart form for the client side.
attribute() adds simple text parts with their names.
fileUpload() adds file parts directly using the existing FileUpload instances from the server.
Additional Notes
ClientMultipartForm is the clean and official way to build multipart form requests on the client side in Quarkus REST Client.
Avoid trying to instantiate or manually implement low-level or server-specific multipart classes like DefaultFileUpload or FormValue.
This approach keeps your code clean and leverages Quarkus's multipart client support.
References
Quarkus REST Client Guide: Converting Received Multipart to Client Request
With this method, you can efficiently upload files from your Quarkus application to any external REST service accepting multipart requests.
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: