[Nativescript] How to use the HttpClient class to download a binary image


#1

Hi,

can you give me an example of using the HttpClient class to download a binary image?

Thanks.


#2

Set responseType to blob in the request.


#3

Thanks again for your help @manojdcoder.

If i set responseType to blob in the request i have this error :

Error: Response type of 'blob' not supported

this is my package.json:

{
	"description": "NativeScript Application",
	"license": "SEE LICENSE IN <your-license-filename>",
	"readme": "NativeScript Application",
	"repository": "<fill-your-repository-here>",
	"nativescript": {
		"tns-android": {
			"version": "3.4.2"
		},
		"tns-ios": {
			"version": "3.4.1"
		}
	},
	"dependencies": {
		"@angular/animations": "~4.4.1",
		"@angular/common": "~4.4.1",
		"@angular/compiler": "~4.4.1",
		"@angular/core": "~4.4.1",
		"@angular/forms": "~4.4.1",
		"@angular/http": "~4.4.1",
		"@angular/platform-browser": "~4.4.1",
		"@angular/router": "~4.4.1",
		"angular2-jwt": "^0.2.3",
		"angular2-moment": "^1.8.0",
		"base-64": "^0.1.0",
		"buffer": "^5.0.8",
		"file-system": "^2.2.2",
		"nativescript-android-utils": "^1.0.2",
		"nativescript-angular": "~4.4.0",
		"nativescript-background-http": "^3.1.0",
		"nativescript-theme-core": "~1.0.2",
		"ng2-translate": "^5.0.0",
		"path": "^0.12.7",
		"reflect-metadata": "~0.1.8",
		"rxjs": "~5.4.2",
		"tns-core-modules": "^3.4.1",
		"utf8": "^3.0.0",
		"zone.js": "~0.8.2"
	},
	"devDependencies": {
		"babel-traverse": "6.4.5",
		"babel-types": "6.4.5",
		"babylon": "6.4.5",
		"lazy": "1.0.11",
		"nativescript-dev-typescript": "~0.5.0",
		"tns-platform-declarations": "^3.4.1",
		"typescript": "~2.4.2"
	}
}


#4

Hope you figured out it’s a known issue, so left with using ImageSource or Http modules for now.


#5

Yes, in fact, I looked and I’m looking around and it seems that for now there is still no solution.
ImageSource for download image?How?


#6

fromUrl static method from ImageSource module.