could transmit a photo finally

This commit is contained in:
2020-10-04 07:39:33 -05:00
parent 778189ce5f
commit 688a156ec2

View File

@@ -119,7 +119,7 @@ static const uint32_t CHUNK_SIZE = 1024;
static const uint32_t MSG_SIZE = 256;
static const char * uploadPath = "/upload";
static const char * server = "192.168.1.107:3001";
static const char * boundary = "01234567899876543210";
static const char * boundary = "boundary";
static void post_data(camera_fb_t * pic){
char url[128];
@@ -129,11 +129,11 @@ static void post_data(camera_fb_t * pic){
esp_http_client_handle_t client = esp_http_client_init(&config);
esp_http_client_set_method(client, HTTP_METHOD_POST);
char header[CHUNK_SIZE];
char head[MSG_SIZE];
char tail[MSG_SIZE];
sprintf(head, "--%s\r\n"
sprintf(head,
"--%s\r\n"
"Content-Disposition: form-data; name=\"photo\"; filename=\"esp32.jpg\"\r\n"
"Content-Type: image/jpeg\r\n\r\n", boundary);
sprintf(tail, "\r\n--%s--\r\n", boundary);
@@ -142,26 +142,31 @@ static void post_data(camera_fb_t * pic){
char tmpStr[MSG_SIZE];
// send header so that the server knows what to do with chunks after this
sprintf(header, "POST %s HTTP/1.1\r\nHost: %s\r\n"
"Content-Length: %u\r\n"
"Expect: 100-continue\r\n"
"Accept: */*\r\n"
"Content-Type: multipart/form-data; boundary=%s\r\n\r\n"
, uploadPath, server, pic->len, boundary);
ESP_LOGI(TAG, "header to be sent:\n%s", header);
sprintf(tmpStr, "%u", totalLen);
esp_http_client_set_header(client, "Content-Length", tmpStr);
ESP_LOGI(TAG, "Content-Length: %s", tmpStr);
esp_http_client_open(client, totalLen);
sprintf(tmpStr, "multipart/form-data; boundary=%s", boundary);
esp_http_client_set_header(client, "Content-Type", tmpStr);
ESP_LOGI(TAG, "Content-Type: %s", tmpStr);
esp_http_client_set_header(client, "Accept", "*/*");
esp_http_client_set_header(client, "Expect", "100-continue");
err_t err;
err = esp_http_client_open(client, totalLen);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_http_client_open failed");
esp_http_client_cleanup(client);
return;
}
// send the first header
esp_http_client_write(client, header, strlen(header));
vTaskDelay(100 / portTICK_RATE_MS);
sprintf(tmpStr, "\r\n");
esp_http_client_write(client, tmpStr, strlen(tmpStr));
vTaskDelay(10 / portTICK_RATE_MS);
esp_http_client_fetch_headers(client);
ESP_LOGI(TAG, "code %d", esp_http_client_get_status_code(client));
/* char resp[CHUNK_SIZE]; */
/* esp_http_client_read(client, resp, CHUNK_SIZE); */
/* ESP_LOGI(TAG, "%s", resp); */
// send head
esp_http_client_write(client, head, strlen(head));
ESP_LOGI(TAG, "%s", (char *)head);