RobinBobin / react-native-google-drive-api-wrapper

This wrapper facilitates the use of the Google Drive API in React Native projects.
110 stars 43 forks source link

How do I properly use getContent? #75

Closed andresmejia3 closed 2 years ago

andresmejia3 commented 2 years ago

I checked out the docs and the sample project but I couldn't find anything that showed how to use it. I'm not sure what type of file I'll be retrieving so I thought getContent would be the best for the job (please correct me if I'm mistaken). However, whenever I call it I get

  '_bodyBlob': {
    '_data': {
      '__collector': [Object],
      'blobId': 'EB2F2B24-F4BD-4F17-B8BB-490EF60EA94C',
      'name': '1qg6_yEIdaZSuIowGYvwq3RQHHAuGyfiC.txt',
      'offset': 0,
      'size': 649,
      'type': 'text/plain'
    }
  },
  '_bodyInit': {
    '_data': {
      '__collector': [Object],
      'blobId': 'EB2F2B24-F4BD-4F17-B8BB-490EF60EA94C',
      'name': '1qg6_yEIdaZSuIowGYvwq3RQHHAuGyfiC.txt',
      'offset': 0,
      'size': 649,
      'type': 'text/plain'
    }
  },
  'bodyUsed': false,
  'headers': {
    'map': {
      'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
      'cache-control': 'private, max-age=0, must-revalidate',
      'content-disposition': 'attachment',
      'content-length': '649',
      'content-type': 'text/plain',
      'date': 'Fri, 02 Sep 2022 02:15:19 GMT',
      'expires': 'Fri, 02 Sep 2022 02:15:19 GMT',
      'server': 'UploadServer',
      'vary': 'Origin, X-Origin',
      'x-goog-hash': 'crc32c=K30HMQ==',
      'x-guploader-uploadid': 'ADPycdsjO4KtRPo1-gjOppXMSrqFvunuLF2gGekad-BGCFqdhGwHEWvin1-j91Mj_zHWM4hzoJtdonDIej8I2aRkg0fgmIx2uf62'
    }
  },
  'ok': true,
  'status': 200,
  'statusText': '',
  'type': 'default',
  'url': 'https://www.googleapis.com/drive/v3/files/1qg6_yEIdaZSuIowGYvwq3RQHHAuGyfiC?alt=media'
}

In this case, the file I'm attempting to retrieve is a text file with Lorem Ipsum, but in production I plan on there being PDFs, images, videos, etc. How do I use the response object to get the contents of the file? Am I better off using get? From a shallow inspection it seems that getContent is calling get but with alt='media'. Thank you!

RobinBobin commented 2 years ago

Please show how you invoke getContent().

andresmejia3 commented 2 years ago

await this.drive.files.getContent(fileID) Where this.drive is a GDrive instance and fileID is a valid ID

RobinBobin commented 2 years ago

Great. I think my supposition was right. Now, this package readme states that getContent()

Returns the result of fetch() if the call succeeds, fetchCoercesTypes is ignored.

My question is: what does await fetch() return?

andresmejia3 commented 2 years ago

Great. I think my supposition was right. Now, this package readme states that getContent()

Returns the result of fetch() if the call succeeds, fetchCoercesTypes is ignored.

My question is: what does await fetch() return?

I see sorry I don't know why I didn't catch it the first time. It returns a response object. So I can just get the data by doing response.body?

RobinBobin commented 2 years ago

That's ok 😉 . Exactly, it's an ordinary fetch.

andresmejia3 commented 2 years ago

That's ok 😉 . Exactly, it's an ordinary fetch.

Gotcha haha thanks again for the great Google API wrapper