私はredux-observableを使用して画像を取得しようとしています。redux-observableを使ってバイナリイメージを正しく取得するには?
Microsoft Graph APIに基づいて、要求された写真のバイナリデータを返します。
私はPostmanを使用して画像を取得することに成功しました(これはバイナリであるため結果の画像を表示します)。しかし
、私は私が得たredux-observable、応答を使用しようと常にnull
で、responseTypeは関係なく、私はimage/jpeg
、text/plain
、application/json
ようのContent-Typeのために与えるものを常にjson
ではありません。
export const getAvatarEpic = (action$, store) =>
action$
.ofType(GET_AVATAR)
.mergeMap(action =>
ajax
.get(
'https://graph.microsoft.com/v1.0/me/photo/$value',
{
// 'Content-Type': 'image/jpeg',
'Authorization': 'Bearer ' + myToken
}
)
.do(res => console.log(res)) // <- the result
.map(getAvatarSucceed)
.catch(getAvatarFailed)
);
これは私が得たものです。多分ajax.get
の代わりに何か他のものを使うべきでしょうか?
{
"originalEvent": {
"isTrusted": true
},
"xhr": {},
"request": {
"async": true,
"crossDomain": false,
"withCredentials": false,
"headers": {
"Authorization": "Bearer hereIsMyToken",
"X-Requested-With": "XMLHttpRequest"
},
"method": "GET",
"responseType": "json",
"timeout": 0,
"url": "https://graph.microsoft.com/v1.0/me/photo/$value"
},
"status": 200,
"responseType": "json",
"response": null
}
必要がありますか画像のMIMEタイプ?例えばなぜjsonは応答タイプですか? – Tim
@Tim yeah、それは良い点です。 [api](https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/profilephoto_get)に基づいて、私は 'Authorization'を提供する必要があります。しかし、実際には、** Content-Type **に 'image/jpeg'、' text/plain'、 'application/json'を追加しようとしましたが、** responseType **は常に' json'です。 –
私はここの「Content-Type」は、レスポンスではなく要求にのみ影響すると考えています。レスポンスの本文にbase64でエンコードされたイメージを戻す必要があります。レスポンスボディも追加できますか? –