Search code examples
angularrxjsmedia-type

RxJS - Angular2 - A watch to fetch Media types


I didn't find this in the documentation of Angular and RxJS. Is there any way to fetch a MediaType (img, video ..) data from an HTTP response an process/download it ?

The problem is that whether with the get or head HTTP method with an image (png) or an XML media type from the backend, I keep having the following HTTP error :

415 Unsupported Media Type

Here is the code, Version 1:

 return this.http.head(this.localBackURL + ressourcesPath.exportStatistiques, {search: params}); 

Version 2 :

 return this.http.head(this.localBackURL + ressourcesPath.exportStatistiques, {search: params}); 

Thanks


Solution

  • I'm not really sure if I understood the problem correctly.

    But to get metadata from something, instead of using the get request method, you can use the head request method.

    You can probably use this to get the information needed to decide if you want to proceed with the get method afterwards.

    If you just want to download the file and then check for the MediaType you can read the headers after getting the file.

    Update A quick google to the Error and I found the following. As there is currently no code for me to look at, I assume you'll probably have similar issues as I found.

    415 Unsupported Media Type - POST json to OData service in lightswitch 2012

    It looks like this Error happens if you have wrong Content-Type and/or wrong Accept Header settings.