You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openmeetings.apache.org by "seba.wagner@gmail.com" <se...@gmail.com> on 2021/01/06 05:32:24 UTC

FileWebService.add send file using Rest always returns 415

I'm trying to upload a file using the Rest API

The result is always 415 Unsupported Media Type

The arguments and path elements match. But somehow the Media Type of the
INputStream/File doesn't match application/octet_stream

It is the same result via trying to upload from a HTML form as it is from
Postman.

Has anybody successfully uploaded a file using the Webservice ?

Thanks
Seb

Sebastian Wagner
Director Arrakeen Solutions
http://arrakeen-solutions.co.nz/
<https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url>
<https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url>

Re: FileWebService.add send file using Rest always returns 415

Posted by Maxim Solodovnik <so...@gmail.com>.
On Thu, 7 Jan 2021 at 08:34, seba.wagner@gmail.com <se...@gmail.com>
wrote:

> Do you have PHP example code?
>

Yes, sure :)

you always can check Moodle plugin
or API:
https://github.com/openmeetings/openmeetings-api-plugin/blob/master/src/main/scripts/OmGateway.php#L294


>
> Invoking via JUnit/Java, it doesn't really demonstrate how to configure the
> HTTP request as it calls it just via Java.
>

Well,
It demonstrates HTTP requests :)

Just run the test and check the logs (full payload will be printed)
You also can check payload at CI server


> It looks to me like the Mime-Type mapping is broken. Although our
> implementation seems to match 100% the the official jax-rs examples for
> MultiPart form handlers.
>

Everything works :)
the tests are green and there no reports from Moodle users :)))


> Cheers
> Seb
>
> Sebastian Wagner
> Director Arrakeen Solutions
> http://arrakeen-solutions.co.nz/
> <
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> >
> <
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> >
>
>
> On Thu, 7 Jan 2021 at 14:04, Maxim Solodovnik <so...@gmail.com>
> wrote:
>
> > Hello Sebastian,
> >
> > this API is covered with JUnit tests so you can check it locally or
> > check the logs at Jenkins
> >
> >
> https://ci-builds.apache.org/job/OpenMeetings/job/openmeetings/217/consoleFull
> > (search for `openmeetings/services/file`)
> >
> > PHP code is also works :)
> >
> > On Thu, 7 Jan 2021 at 03:08, seba.wagner@gmail.com <
> seba.wagner@gmail.com>
> > wrote:
> >
> > > yes also with jpeg. Any file type. With Postman as well as via HTML
> form
> > > submit.
> > >
> > > Or you can also trigger it via curl:
> > > curl --location --request POST '
> > > http://127.0.0.1:5080/openmeetings/services/file' \
> > > --header 'Accept: application/json' \
> > > --header 'Content-Type: application/json' \
> > > --form 'sid="asdasdasd"' \
> > > --form 'stream=@"/Users/Sebastian.wagner/Pictures/my.jpeg"' \
> > > --form 'file=@"/Users/Sebastian.wagner/Documents/my.json"'
> > >
> > > Results:
> > > WARN  01-07 09:02:03.118 o.a.c.j.i.WebApplicationExceptionMapper:73
> > > [p1966418217-143] - javax.ws.rs.ClientErrorException: HTTP 415
> > Unsupported
> > > Media Type
> > > at
> > >
> > >
> >
> org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
> > > at
> > >
> > >
> >
> org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:168)
> > > at
> > >
> >
> org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:516)
> > > at
> > >
> > >
> >
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
> > >
> > > Removing the headers has no effect. Same exception. Digging through the
> > > exception stack
> > > => JAXRSUtils.java:516 => It just can't find a method that matches the
> > > method signature based on the MediaType. It can match the path.
> > >
> > > But it can't match the arguments for the "stream" argument: type =
> > > MediaType.APPLICATION_OCTET_STREAM
> > >
> > > It is NOT this type. So the method won't match and jax-rs responses.
> You
> > > can set a breakpoint into the code and you will see that the payload
> has
> > a
> > > different type.
> > >
> > > "file" is fine. It can parse and match the json MediaType. But not
> > > octet_stream.
> > >
> > > Thanks
> > > Seb
> > >
> > > Sebastian Wagner
> > > Director Arrakeen Solutions
> > > http://arrakeen-solutions.co.nz/
> > > <
> > >
> >
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> > > >
> > > <
> > >
> >
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> > > >
> > >
> > >
> > > On Thu, 7 Jan 2021 at 00:29, Daniel Baker <info@collisiondetection.biz
> >
> > > wrote:
> > >
> > > > Same  result  with  JPEG ?
> > > >
> > > > On 06-Jan-21 5:32 AM, seba.wagner@gmail.com wrote:
> > > > > I'm trying to upload a file using the Rest API
> > > > >
> > > > > The result is always 415 Unsupported Media Type
> > > > >
> > > > > The arguments and path elements match. But somehow the Media Type
> of
> > > the
> > > > > INputStream/File doesn't match application/octet_stream
> > > > >
> > > > > It is the same result via trying to upload from a HTML form as it
> is
> > > from
> > > > > Postman.
> > > > >
> > > > > Has anybody successfully uploaded a file using the Webservice ?
> > > > >
> > > > > Thanks
> > > > > Seb
> > > > >
> > > > > Sebastian Wagner
> > > > > Director Arrakeen Solutions
> > > > > http://arrakeen-solutions.co.nz/
> > > > > <
> > > >
> > >
> >
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> > > > >
> > > > > <
> > > >
> > >
> >
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> > > > >
> > > > >
> > > >
> > >
> >
> >
> > --
> > Best regards,
> > Maxim
> >
>


-- 
Best regards,
Maxim

Re: FileWebService.add send file using Rest always returns 415

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
Do you have PHP example code?

Invoking via JUnit/Java, it doesn't really demonstrate how to configure the
HTTP request as it calls it just via Java.

It looks to me like the Mime-Type mapping is broken. Although our
implementation seems to match 100% the the official jax-rs examples for
MultiPart form handlers.

Cheers
Seb

Sebastian Wagner
Director Arrakeen Solutions
http://arrakeen-solutions.co.nz/
<https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url>
<https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url>


On Thu, 7 Jan 2021 at 14:04, Maxim Solodovnik <so...@gmail.com> wrote:

> Hello Sebastian,
>
> this API is covered with JUnit tests so you can check it locally or
> check the logs at Jenkins
>
> https://ci-builds.apache.org/job/OpenMeetings/job/openmeetings/217/consoleFull
> (search for `openmeetings/services/file`)
>
> PHP code is also works :)
>
> On Thu, 7 Jan 2021 at 03:08, seba.wagner@gmail.com <se...@gmail.com>
> wrote:
>
> > yes also with jpeg. Any file type. With Postman as well as via HTML form
> > submit.
> >
> > Or you can also trigger it via curl:
> > curl --location --request POST '
> > http://127.0.0.1:5080/openmeetings/services/file' \
> > --header 'Accept: application/json' \
> > --header 'Content-Type: application/json' \
> > --form 'sid="asdasdasd"' \
> > --form 'stream=@"/Users/Sebastian.wagner/Pictures/my.jpeg"' \
> > --form 'file=@"/Users/Sebastian.wagner/Documents/my.json"'
> >
> > Results:
> > WARN  01-07 09:02:03.118 o.a.c.j.i.WebApplicationExceptionMapper:73
> > [p1966418217-143] - javax.ws.rs.ClientErrorException: HTTP 415
> Unsupported
> > Media Type
> > at
> >
> >
> org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
> > at
> >
> >
> org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:168)
> > at
> >
> org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:516)
> > at
> >
> >
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
> >
> > Removing the headers has no effect. Same exception. Digging through the
> > exception stack
> > => JAXRSUtils.java:516 => It just can't find a method that matches the
> > method signature based on the MediaType. It can match the path.
> >
> > But it can't match the arguments for the "stream" argument: type =
> > MediaType.APPLICATION_OCTET_STREAM
> >
> > It is NOT this type. So the method won't match and jax-rs responses. You
> > can set a breakpoint into the code and you will see that the payload has
> a
> > different type.
> >
> > "file" is fine. It can parse and match the json MediaType. But not
> > octet_stream.
> >
> > Thanks
> > Seb
> >
> > Sebastian Wagner
> > Director Arrakeen Solutions
> > http://arrakeen-solutions.co.nz/
> > <
> >
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> > >
> > <
> >
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> > >
> >
> >
> > On Thu, 7 Jan 2021 at 00:29, Daniel Baker <in...@collisiondetection.biz>
> > wrote:
> >
> > > Same  result  with  JPEG ?
> > >
> > > On 06-Jan-21 5:32 AM, seba.wagner@gmail.com wrote:
> > > > I'm trying to upload a file using the Rest API
> > > >
> > > > The result is always 415 Unsupported Media Type
> > > >
> > > > The arguments and path elements match. But somehow the Media Type of
> > the
> > > > INputStream/File doesn't match application/octet_stream
> > > >
> > > > It is the same result via trying to upload from a HTML form as it is
> > from
> > > > Postman.
> > > >
> > > > Has anybody successfully uploaded a file using the Webservice ?
> > > >
> > > > Thanks
> > > > Seb
> > > >
> > > > Sebastian Wagner
> > > > Director Arrakeen Solutions
> > > > http://arrakeen-solutions.co.nz/
> > > > <
> > >
> >
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> > > >
> > > > <
> > >
> >
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> > > >
> > > >
> > >
> >
>
>
> --
> Best regards,
> Maxim
>

Re: FileWebService.add send file using Rest always returns 415

Posted by Maxim Solodovnik <so...@gmail.com>.
Hello Sebastian,

this API is covered with JUnit tests so you can check it locally or
check the logs at Jenkins
https://ci-builds.apache.org/job/OpenMeetings/job/openmeetings/217/consoleFull
(search for `openmeetings/services/file`)

PHP code is also works :)

On Thu, 7 Jan 2021 at 03:08, seba.wagner@gmail.com <se...@gmail.com>
wrote:

> yes also with jpeg. Any file type. With Postman as well as via HTML form
> submit.
>
> Or you can also trigger it via curl:
> curl --location --request POST '
> http://127.0.0.1:5080/openmeetings/services/file' \
> --header 'Accept: application/json' \
> --header 'Content-Type: application/json' \
> --form 'sid="asdasdasd"' \
> --form 'stream=@"/Users/Sebastian.wagner/Pictures/my.jpeg"' \
> --form 'file=@"/Users/Sebastian.wagner/Documents/my.json"'
>
> Results:
> WARN  01-07 09:02:03.118 o.a.c.j.i.WebApplicationExceptionMapper:73
> [p1966418217-143] - javax.ws.rs.ClientErrorException: HTTP 415 Unsupported
> Media Type
> at
>
> org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
> at
>
> org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:168)
> at
> org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:516)
> at
>
> org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)
>
> Removing the headers has no effect. Same exception. Digging through the
> exception stack
> => JAXRSUtils.java:516 => It just can't find a method that matches the
> method signature based on the MediaType. It can match the path.
>
> But it can't match the arguments for the "stream" argument: type =
> MediaType.APPLICATION_OCTET_STREAM
>
> It is NOT this type. So the method won't match and jax-rs responses. You
> can set a breakpoint into the code and you will see that the payload has a
> different type.
>
> "file" is fine. It can parse and match the json MediaType. But not
> octet_stream.
>
> Thanks
> Seb
>
> Sebastian Wagner
> Director Arrakeen Solutions
> http://arrakeen-solutions.co.nz/
> <
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> >
> <
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> >
>
>
> On Thu, 7 Jan 2021 at 00:29, Daniel Baker <in...@collisiondetection.biz>
> wrote:
>
> > Same  result  with  JPEG ?
> >
> > On 06-Jan-21 5:32 AM, seba.wagner@gmail.com wrote:
> > > I'm trying to upload a file using the Rest API
> > >
> > > The result is always 415 Unsupported Media Type
> > >
> > > The arguments and path elements match. But somehow the Media Type of
> the
> > > INputStream/File doesn't match application/octet_stream
> > >
> > > It is the same result via trying to upload from a HTML form as it is
> from
> > > Postman.
> > >
> > > Has anybody successfully uploaded a file using the Webservice ?
> > >
> > > Thanks
> > > Seb
> > >
> > > Sebastian Wagner
> > > Director Arrakeen Solutions
> > > http://arrakeen-solutions.co.nz/
> > > <
> >
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> > >
> > > <
> >
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> > >
> > >
> >
>


-- 
Best regards,
Maxim

Re: FileWebService.add send file using Rest always returns 415

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
yes also with jpeg. Any file type. With Postman as well as via HTML form
submit.

Or you can also trigger it via curl:
curl --location --request POST '
http://127.0.0.1:5080/openmeetings/services/file' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--form 'sid="asdasdasd"' \
--form 'stream=@"/Users/Sebastian.wagner/Pictures/my.jpeg"' \
--form 'file=@"/Users/Sebastian.wagner/Documents/my.json"'

Results:
WARN  01-07 09:02:03.118 o.a.c.j.i.WebApplicationExceptionMapper:73
[p1966418217-143] - javax.ws.rs.ClientErrorException: HTTP 415 Unsupported
Media Type
at
org.apache.cxf.jaxrs.utils.SpecExceptions.toHttpException(SpecExceptions.java:117)
at
org.apache.cxf.jaxrs.utils.ExceptionUtils.toHttpException(ExceptionUtils.java:168)
at
org.apache.cxf.jaxrs.utils.JAXRSUtils.findTargetMethod(JAXRSUtils.java:516)
at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:181)

Removing the headers has no effect. Same exception. Digging through the
exception stack
=> JAXRSUtils.java:516 => It just can't find a method that matches the
method signature based on the MediaType. It can match the path.

But it can't match the arguments for the "stream" argument: type =
MediaType.APPLICATION_OCTET_STREAM

It is NOT this type. So the method won't match and jax-rs responses. You
can set a breakpoint into the code and you will see that the payload has a
different type.

"file" is fine. It can parse and match the json MediaType. But not
octet_stream.

Thanks
Seb

Sebastian Wagner
Director Arrakeen Solutions
http://arrakeen-solutions.co.nz/
<https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url>
<https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url>


On Thu, 7 Jan 2021 at 00:29, Daniel Baker <in...@collisiondetection.biz>
wrote:

> Same  result  with  JPEG ?
>
> On 06-Jan-21 5:32 AM, seba.wagner@gmail.com wrote:
> > I'm trying to upload a file using the Rest API
> >
> > The result is always 415 Unsupported Media Type
> >
> > The arguments and path elements match. But somehow the Media Type of the
> > INputStream/File doesn't match application/octet_stream
> >
> > It is the same result via trying to upload from a HTML form as it is from
> > Postman.
> >
> > Has anybody successfully uploaded a file using the Webservice ?
> >
> > Thanks
> > Seb
> >
> > Sebastian Wagner
> > Director Arrakeen Solutions
> > http://arrakeen-solutions.co.nz/
> > <
> https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url
> >
> > <
> https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url
> >
> >
>

Re: FileWebService.add send file using Rest always returns 415

Posted by Daniel Baker <in...@collisiondetection.biz>.
Same  result  with  JPEG ?

On 06-Jan-21 5:32 AM, seba.wagner@gmail.com wrote:
> I'm trying to upload a file using the Rest API
>
> The result is always 415 Unsupported Media Type
>
> The arguments and path elements match. But somehow the Media Type of the
> INputStream/File doesn't match application/octet_stream
>
> It is the same result via trying to upload from a HTML form as it is from
> Postman.
>
> Has anybody successfully uploaded a file using the Webservice ?
>
> Thanks
> Seb
>
> Sebastian Wagner
> Director Arrakeen Solutions
> http://arrakeen-solutions.co.nz/
> <https://www.youracclaim.com/badges/da4e8828-743d-4968-af6f-49033f10d60a/public_url>
> <https://www.youracclaim.com/badges/b7e709c6-aa87-4b02-9faf-099038475e36/public_url>
>