1

I'm having a bit of a problem putting some pieces together in an app I'm building. I'm using React-Native, and have the camera storing an image.

There are two ways I can get Microsoft's Face API to evaluate an image:

  1. External URL
  2. octet-stream

Since the app does not upload the photo from your mobile phone to a server, I have to rely on octet-stream. Unfortunately, Microsoft does not have documentation on how to do this in JavaScript.

At this point, I just have the fetch API to do all my network requests. I've been looking online for tutorials, but can't figure out how to orchestrate these steps:

  1. Camera takes an image and stores it in a local file (I can grab the file path to the image -- this step is good).
  2. Use fetch using octet-stream to send the file to the Face API.

Using octet-stream, does this mean I need to use a Buffer object to read the file and place it into the fetch request?

Thanks for any and all help!

EHorodyski
  • 774
  • 1
  • 8
  • 30
  • don't use `fetch`, because you can't "stream" using fetch – Jaromanda X May 02 '19 at 23:32
  • yeesh...how about `axios`? – EHorodyski May 03 '19 at 00:51
  • @JaromandaX actually per specs [fetch can now send ReadableStreams](https://github.com/whatwg/fetch/pull/425) (even though [nobody supports this currently](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request#Browser_compatibility)) But anyway, EHordyski, do you really want to **"stream"** it? Don't you just want to upload it? If so, then you are just asking [how to send a file to a server](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data). – Kaiido May 03 '19 at 01:28
  • so, @Kaiido - what you're saying is, you can't "stream" using fetch – Jaromanda X May 03 '19 at 01:44
  • @JaromandaX ..."currently" Per specs you can. And in the future you will be able to do it. And to be totally pedantic, you can actually already *stream* from the server using fetch. – Kaiido May 03 '19 at 01:45
  • I thought the OP wanted to stream **to** the server, today, using fetch? Did I read the question wrong – Jaromanda X May 03 '19 at 01:56
  • @JaromandaX Well I think they didn't explain themselves correctly and you focused on the term *stream* while all they want is actually to post this image. MS Face Cognitive Services API expects a simple HTTP POST request. My comment was just an heads up on your own that not only was mislead by OP's use of the term *stream*, but also kind of incorrect. – Kaiido May 03 '19 at 02:26
  • What does "storing an image" exactly means? Do you have a .jpeg image file saved on your server? Then [Face API accepts URIs directly](https://westus.dev.cognitive.microsoft.com/docs/services/563879b61984550e40cbbe8d/operations/563879b61984550f30395236). – Kaiido May 03 '19 at 02:30
  • @Kaiido - perhaps I misunderstood the question by reading the words used in the question - however, I didn't misunderstand the fact *Send ReadableStream in request body* is not supported and therefore can not be done. – Jaromanda X May 03 '19 at 03:33
  • This is why I shouldn't rush StackOverflow questions! Since the Face API can either take a URL (which wouldn't exist because the image is stored locally on the user's mobile device) or an `octet-stream`, I presumed I would need to do the latter, and I thought behind-the-scenes what the request does is stream a file in chunks). My mistake guys! – EHorodyski May 03 '19 at 11:16
  • I've updated my question, hopefully it makes more sense. It's a mobile device, so the file is stored on device. I need to use the Face API's `octet-stream` option in order to get this file to it, since there is no external URL I am pushing to a server. – EHorodyski May 03 '19 at 11:48

0 Answers0