2017-03-29 13 views
0

javascriptでダウンロードしようとしたときにダウンロードしたい画像がありますjavascript refererが必要な画像をダウンロードする

しかし、私は以下のようなpythonコードで画像をダウンロードできます。ヘッダーにリファラーを追加してダウンロードします。

req = urllib.request.Request(image_url, headers={"Referer": referer_url}) 
with urllib.request.urlopen(req) as response, open("image.jpg", "wb") as outfile: 
    shutil.copyfileobj(response, outfile) 

JavaScriptはこのような画像をダウンロードできますか?

Javascriptコード私は試しています。その反応ネイティブ・フェッチ・ブロブlibaray

export const saveToonImageToLocal = (url, imageName) => { 
    return RNFetchBlob 
    .config({ 
     path: dirs.DocumentDir + `${imageName}.jpg`, 
     appendExt: 'jpg' 
    }) 
    .fetch('GET', url, {}) 
    .then((res)=>{ 
     return res.path(); 
    }) 
    .catch((e)=>{ 
     console.log('error occurend during saving images'); 
    }) 
}; 
+0

あなたはJavascriptを追加することができ、あなたの質問に使用していますか? – wogsland

+0

[xml.HTTP.RequestのためのRefererを設定しますか?](http://stackoverflow.com/questions/27218525/set-referer-for-xml-http-request) – gyre

答えて

0

あなたはそれでJavaScriptのAJAX呼び出しとパッシングのヘッダーを使用して画像を読み込むことができます。

$.ajax({ 
    type:'GET', 
    url:'https://example.com/someimage.png', 
    headers: {'Referer': "http://somepage.com"}, 
    success:function(data){ 
     $('#someImage').attr('src',data); 
    } 
    }); 
関連する問題