Forum Discussion
ponelat
3 years agoStaff
Hi ubaidshahid
I'm no Java expert.
OpenAPI v3 has changed the way it handles file uploads (via Multipart) away from `paramters` and into `requestBody`.
This example may help...
package io.swagger.v3.jaxrs2.it.resources;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import org.glassfish.jersey.media.multipart.FormDataParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.InputStream;
@Path("/files")
@Produces("application/json")
public class MultiPartFileResource {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(@FormDataParam("fileIdRenamed") final String fileId,
@Parameter(schema = @Schema(type = "string", format = "binary")) @FormDataParam("fileRenamed") final InputStream file) {
return Response.status(200).entity("File " + fileId + " has been uploaded").build();
}
}
- ubaidshahid3 years agoNew Contributor
Thanks for giving me some solution advice, but this same thing i replicated to my code editor and tried to run, but it is not showing file attribute on swagger UI, it is just showing the
fileIdRename attribute not fileRename attribute
Related Content
Recent Discussions
- 4 hours agotdog
- 2 days agonoob_Vibes