React Native:如何使用fetch从服务器获取Blob

时间:2019-04-30 00:46:43

标签: react-native blob fetch

你好,我尝试从服务器下载blob,这就是我从图像URL中获得的。该网址确实会在浏览器上加载图片。

   Reponse Response {
[12:32:51]   "_bodyInit": "",
[12:32:51]   "_bodyText": "",
[12:32:51]   "headers": Headers {
[12:32:51]     "map": Object {
[12:32:51]       "cache-control": "public, max-age=0",
[12:32:51]       "content-length": "316656",
[12:32:51]       "content-md5": "recjljLrlvrIQJe2sf+3ug==",
[12:32:51]       "content-type": "image/jpg",
[12:32:51]       "date": "Tue, 30 Apr 2019 00:32:50 GMT",
[12:32:51]       "etag": "0x8D6BFA5FD6B1396",
[12:32:51]       "last-modified": "Sat, 13 Apr 2019 00:21:36 GMT",
[12:32:51]       "server": "Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0",
[12:32:51]       "x-ms-blob-type": "BlockBlob",
[12:32:51]       "x-ms-lease-status": "unlocked",
[12:32:51]       "x-ms-request-id": "44fd10dd-801e-0048-65ec-fedcca000000",
[12:32:51]       "x-ms-version": "2009-09-19",
[12:32:51]     },
[12:32:51]   },
[12:32:51]   "ok": true,
[12:32:51]   "status": 200,
[12:32:51]   "statusText": undefined,
[12:32:51]   "type": "default",
[12:32:51]   "url": "feed-media/56a11ddd-291c-4037-bcdd-240990305325.jpg",
[12:32:51] }

在此处使用代码:

var settings = {
    method: "GET",
    headers: {
      'Accept': 'image/*',
      'Content-Type': 'application/octet-stream'
    }
  };

  const response = await fetch(uri, settings); 
  console.log("Reponse", response)
  const blob = await response.blob(); 

并且收到了blob对象:

   Blob Path Blob {
[12:15:13]   "_data": Object {
[12:15:13]     "blobId": "0597099d-b645-4b0e-882a-dc802fc71bf3",
[12:15:13]     "lastModified": 1556583312936,
[12:15:13]     "offset": 0,
[12:15:13]     "size": 220,
[12:15:13]     "type": "",
[12:15:13]   },
[12:15:13] }

似乎其中没有数据。

0 个答案:

没有答案