Home > OS >  Not getting response from AWS after uploading image through ESP32
Not getting response from AWS after uploading image through ESP32

Time:07-01

General context: I am working on an IoT application where I upload images from an ESP32 connected to an SBC. The uploading is done through an API provided by a third-party backend developer. The upload API works through other mediums (such as Postman, python requests library, python http client library)

The ESP32 is connected to the SBC through UART. I construct/generate the HTTP request on the SBC and send it as bytes. I have written a function on ESP32 that can send the bytes as a generic HTTP request, to the URL specified. Then it sends the response string back to the SBC.

All of this works. For small requests, I am facing no issues. I am able to download images, etc.

However, when uploading an image, I don't get a response and I end up timing out after 30s. I checked without timeout FYI, but no response.

I checked from the server-side. It appears my request has succeeded and the server is sending me 200 with the URL of the image. Using that URL, I was able to verify that the image was uploaded successfully.

However, I do not receive this response on the microcontroller.

Not sure what the issue is. Any suggestions as to what I can do?

I can't give out the code but I'll send a general structure:

ESP32

-> Receives URL, port, length of request
-> Connects to server and reads the request from UART and writes to server
-> Wait for response after response is sent

Python raw http

POST (server path) HTTP/1.1
Host: (url)
correlation-id: test5
Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWxkTrZu0gW
Authorization: Bearer (access token)
Content-Length: 268

--WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="portraits"; filename="name"
Content-Type: image/jpeg

(data)
--WebKitFormBoundary7MA4YWxkTrZu0gW--

Edit 1: So, turns out it is not only "upload image", some other requests are also behaving similarly. Our server has many microservices. The services written in nodeJS which have more than 1 redirects are not working...?

CodePudding user response:

I figured out what the issue is and hopefully, it will help anyone else facing the same issue. Also, some of my requests to the backend server which used a different authentication method worked

I had been generating the raw HTTP using postman code generation but it turns out Postman doesn't add a few headers which are needed for communicating with more complex servers.

What I mean is that if I host a local server, the above code will work. I had already tested it that way

What solved my problem is adding these headers:

POST (server path) HTTP/1.1
Host: (server URL)
User-Agent: ESP32
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
correlation-id: test
Authorization: Bearer (access_token)
Content-Length: 146360
Content-Type: multipart/form-data; boundary=af59ef02d60cd0efefb7bc03db1f4ffc


--af59ef02d60cd0efefb7bc03db1f4ffc
Content-Disposition: form-data; name="portraits"; filename="(name)"
Content-Type: image/jpeg

(data)
--af59ef02d60cd0efefb7bc03db1f4ffc--
  • Related