Hi.
I've been trying to do HTTP POST for large file for some time now. Apparently curl libraries are so dominant, that there's quite little examples how to do it _without curl_.
What I've understood is that you need to add block size string in hex form to start of each block followed with CRLF. Then the payload.
Code:
const static char *synth_header = "POST /v1/avs/speechrecognizer/recognize HTTP/1.1\r\n\
Host: access-alexa-na.amazon.com\r\n\
Authorization: Bearer Atza|Iw...\r\n\
Content-Type: multipart/form-data; boundary=BOUNDARY1234\r\n\
Expect: 100-continue\r\n\
Transfer-Encoding: chunked\r\n\r\n";
const static char *synth_payload = "--BOUNDARY1234\r\n\
Content-Disposition: form-data; name=\"metadata\"\r\n\
Content-Type: application/json; charset=UTF-8\r\n\r\n\
{\"messageHeader\":{},\"messageBody\": {\"profile\": \"alexa-close-talk\",\"locale\": \"en-us\",\"format\": \"audio/L16; rate=16000; channels=1\"}}\r\n\r\n\
--BOUNDARY1234\r\n\
Content-Disposition: form-data; name=\"audio\"\r\n\
Content-Type: audio/L16; rate=16000; channels=1\r\n\r\n";
const static char* boundary_term = "\r\n--BOUNDARY1234--\r\n";
const static char* end_chunk = "0\r\n\r\n";
I first send the synth header and wait for the 100-continue response. Then I send the synth_payload (with the chunk size). After that I'm sending first real audio blob as payload (again with chunk size). After x amount of blobs I'm sending the end_end chunk.
The code is based on openssl socket example (I can post more code samples, but it's rather simple, but longish). I'm trying to reproduce this alexa curl example without curl:
https://miguelmota.com/blog/alexa-vo...ice-with-curl/
Problem is that every time I get 100-continue OK, but after sending the chunks I just get 400 bad request without any further info. So the authentication should be OK. I'm quite sure I'm messing up the chunking somehow. And system I'm using this can only do 1k transfers at the time, so I have to do some sort of chunking.
Curl response:
Code:
* ALPN, server accepted to use http/1.1
> POST /v1/avs/speechrecognizer/recognize HTTP/1.1
> Host: access-alexa-na.amazon.com
> User-Agent: curl/7.47.0
> Accept: */*
> Authorization: Bearer Atza|I...
> Content-Type: multipart/form-data; boundary=BOUNDARY1234
> Content-Length: 50385
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
} [16384 bytes data]
* We are completely uploaded and fine
100 50385 0 0 100 50385 0 26405 0:00:01 0:00:01 --:--:-- 26393< HTTP/1.1 200 OK
< Server: Server
< Date: Tue, 09 May 2017 13:38:43 GMT
< Content-Type: multipart/related; boundary=873c15a5-9d98-4e35-9e50-070af24e6b2c; start=metadata.1494337123714; type="application/json"
< Transfer-Encoding: chunked
< Connection: keep-alive
< x-amzn-RequestId: d0fff283-34bc-11e7-822f-ef09982f8b0b
< Vary: Accept-Encoding,User-Agent
<
{ [405 bytes data]
100 63265 0 12880 100 50385 4371 17098 0:00:02 0:00:02 --:--:-- 17097