Yanıt, görüntü verisine sahip ancak yanıtı ayıklayamıyorum.Görüntü Verisini Ayıklamadan Yanıt: Angular2
MÜŞTERİ Kodunuzu
download() {
this._http.get('http://localhost:9000/download/' + this._fileid)
.subscribe(
data => {
this.image = data;
},
err => console.log('Error is..:' + err)
);
}
SUNUCU Kodunuzu
app.get('/download/:fileid', function(req, res) {
var id = req.params.fileid;
res.set('Content-Type', 'image/jpeg');
gfs.createReadStream({_id: id}).pipe(res);
});
[DÜZENLEME] - Ben CustomXhr kullanmak için kodumu adapte ama gelmiş hiçbir veri ile boş bir damla olsun ancak.
ÖZEL XHR Kodunuzu
@Injectable()
export class CustomBrowserXhr extends BrowserXhr {
build(): any {
let xhr = super.build();
xhr.responseType = "blob";
return <any>(xhr);
}
}
BOOTSTRAP Kodunuzu ihracat fonksiyonu ana (initialHmrState ?: herhangi): Promise {
return bootstrap(App, [
...ENV_PROVIDERS,
...PROVIDERS,
...DIRECTIVES,
...PIPES,
...APP_PROVIDERS,
provide(BrowserXhr, { useClass: CustomBrowserXhr })
])
.catch(err => console.error(err));
HTTP request-
download() {
this._http.get('http://localhost:9000/download/' + this._fileid)
.toPromise()
.then(res => {
if (res.headers.get("Content-Type").startsWith("image/")) {
var blob = new Blob([new Uint8Array(res._body)], {
type: res.headers.get("Content-Type")
});
var urlCreator = window.URL;
var url = urlCreator.createObjectURL(blob);
console.log(url);
this.image = url;
}
})
}
Teşekkür Abdulrahman. Sizin yönteminiz çalışıyor. – shiv
@shiv Size memnuniyetle bekliyoruz, elbette bu 'arrayBuffer' veya 'blob 'angular2 – Abdulrahman