1

I'm trying to implement FormParam annotation support for a lightweight jax-rs engine. There I want to support FormParam("") File type of service implementation with multipart/form-data

According to the jax-rs spec there is a ParamConverterProvider and ParamConverter interfaces for the conversion purposes. But the method accept a string.

@Override
public Object fromString(String s) {
     //
}

Is it a good approach to use this for File? If not what should be the better approach. At the moment I don't use any converters for java.io.File but just parse as it is.

  • `@FormParam` is for `application/x-www-form-urlencoded` data, which is only ASCII character, which at the application level is a String. That's why it allows for only String. The param converter is is used for only `@XxxParam` annotations all of which only can contain Strings in there values, e.g. Headers, Query strings, URL form encoded data. – Paul Samsotha Jun 09 '16 at 05:54
  • What exactly are you trying to accomplish? Your question is not very clear as what you want to happen – Paul Samsotha Jun 09 '16 at 05:54
  • If you are trying to actually use multipart, just use the multipart feature that would specific to your JAX-RS implementation. You don't need to try and create your own deserialization. If you just want to accept a single file, you an use `application/octet-stream` as the content-type and you can accept `File`, `InputStream`, or `byte[]` already out of the box – Paul Samsotha Jun 09 '16 at 06:00
  • @peeskillet I'm trying to implement FormParam to support File objects with multipart/form-data requests. – Thusitha Thilina Dayaratne Jun 09 '16 at 09:52
  • Why? It's not possible. Even if it was, why would you want to do it yourself? Parsing multipart requests is not an easy task. Every JAX-RS implementation already multipart support. What implementation are you using? Maybe I can direct you to the documentation for that implementation. – Paul Samsotha Jun 09 '16 at 09:57
  • @peeskillet I'm actually trying to provide FormParam support for a own jaxrs engine :) – Thusitha Thilina Dayaratne Jun 09 '16 at 13:06

1 Answers1

0

I think you are uploading a file Use @FormDataParam

@FormDataParam("file") InputStream file,
@FormDataParam("file") FormDataContentDisposition fileDisposition

See FileUpload with JaxRs

Community
  • 1
  • 1
Sangram Jadhav
  • 2,438
  • 16
  • 17