Arduino将sdcard中的图像文件上载到azure

Arduino将sdcard中的图像文件上载到azure,azure,arduino,multipart,Azure,Arduino,Multipart,我有一个问题,arduino将SD卡中的文件上载到MS azure认知服务,例如使用图像文件进行面部识别。我已经尝试使用多部分http post上传,它对其他服务有用,但对MS azure不有用。 是否有人有使用应用程序/八位字节流将文件上载到Azure服务器的经验 我的多部分post函数如下所示: void wifisendfile() { //connect to wifi WiFi.begin(ssid.c_str(), pass.c_str()); Serial.print("

我有一个问题,arduino将SD卡中的文件上载到MS azure认知服务,例如使用图像文件进行面部识别。我已经尝试使用多部分http post上传,它对其他服务有用,但对MS azure不有用。 是否有人有使用应用程序/八位字节流将文件上载到Azure服务器的经验

我的多部分post函数如下所示:

void wifisendfile()
{
 //connect to wifi
  WiFi.begin(ssid.c_str(), pass.c_str());
  Serial.print("Attempting to connect to SSID: ");
  Serial.println(ssid);

  while (WiFi.status() != WL_CONNECTED) 
  {
    Serial.print(".");
    // wait 0.5 second for connection:
    delay(500);
  }
  Serial.print("Wifi Connected,IP address: ");
  Serial.println(WiFi.localIP());
//prepare httpclient

  Serial.println("Starting connection to server...");
  Serial.println(host);
  WiFiClient client;

//start http sending
  if (client.connect(host.c_str(), 80)) 
  {
//open file  
  myFile = SD.open("/pic.jpg");
  int filesize=myFile.size();
  Serial.print("filesize=");
  Serial.println(filesize);
  String fileName = myFile.name();
  String fileSize = String(myFile.size());

    Serial.println("reading file");
    if (myFile) 
    {
      String boundary = "CustomizBoundarye----";
      String contentType = "image/jpeg";
 // post header
      String postHeader = "POST " + url + " HTTP/1.1\r\n";
      postHeader += "Host: " + host + ":80 \r\n";
      postHeader += "Content-Type: multipart/form-data; boundary=" + boundary + "\r\n";
     postHeader += "Accept-Charset: utf-8;\r\n";
      String keyHeader = "--" + boundary + "\r\n";
      keyHeader += "Content-Disposition: form-data; name=\"key\"\r\n\r\n";
      String requestHead = "--" + boundary + "\r\n";
      requestHead += "Content-Disposition: form-data; name=\"\"; filename=\"" + fileName + "\"\r\n";
      requestHead += "Content-Type: " + contentType + "\r\n\r\n";

// post tail
     String tail = "\r\n--" + boundary + "--\r\n\r\n";

// content length
      int contentLength = keyHeader.length() + requestHead.length() + myFile.size() + tail.length();
  postHeader += "Content-Length: " + String(contentLength, DEC) + "\n\n";

// send post header
      char charBuf0[postHeader.length() + 1];
      postHeader.toCharArray(charBuf0, postHeader.length() + 1);
      client.write(charBuf0);
      //Serial.print("send post header=");
      //Serial.println(charBuf0);

// send key header
      char charBufKey[keyHeader.length() + 1];
      keyHeader.toCharArray(charBufKey, keyHeader.length() + 1);
      client.write(charBufKey);
      //Serial.print("send key header=");
      //Serial.println(charBufKey);

// send request buffer
      char charBuf1[requestHead.length() + 1];
      requestHead.toCharArray(charBuf1, requestHead.length() + 1);
      client.write(charBuf1);
      //Serial.print("send request buffer=");
      //Serial.println(charBuf1);

// create buffer
      const int bufSize = 2048;
      byte clientBuf[bufSize];
      int clientCount = 0;

// read myFile until there's nothing else in it:
      while (myFile.available()) 
      {
        clientBuf[clientCount] = myFile.read();
        clientCount++;
        if (clientCount > (bufSize - 1)) 
        {
          client.write((const uint8_t *)clientBuf, bufSize);
          clientCount = 0;
        }
      }
      if (clientCount > 0) 
      {
        client.write((const uint8_t *)clientBuf, clientCount);
        //Serial.println("Sent LAST buffer");
      }

// send tail
      char charBuf3[tail.length() + 1];
      tail.toCharArray(charBuf3, tail.length() + 1);
      client.write(charBuf3);
      //Serial.print(charBuf3);
    } 
    Serial.println("end_request");

 }
  String lastline;
  while(client.connected())
  {
    while(client.available()) 
    {
        String line = client.readStringUntil('\r');
        lastline=line;
        //Serial.print(line);
        if(line.indexOf("{")>0)
        {
          client.stop();
        }        
    }
 }
 Serial.println(lastline);
 myFile.close();
 Serial.println("closing connection");

}

经过几天的尝试,我使用嗅探器扫描网络中的包数据。我发现任何数据都必须通过https发送到Azure服务。所以任何文件上传都失败了。在使用HTTPS后,文件可以正常上传,并从azure服务器获得响应

既然你已经解决了你的问题,请发布一个正确的答案,而不是评论,这样这个问题就可以正确地结束。