0

这里发送的数据被插入到数据库中的一个表中,图像被插入到另一个表中。用户向多个图像选择器发送请求。否则无论选择多少张图片,表格中只会插入一张图片。

是否可以将所有选定的图像表插入表中,而只插入其他数据一次?

Insert(String queID, siteId, int rating, String discription,
    String supervisorID, List images) async {
  
    for (var i = 0; i < images.length; i++) {
      ByteData byteData = await images[i].getByteData();
      List<int> imageData = byteData.buffer.asInt8List();

      MultipartFile multipartFile = MultipartFile.fromBytes('image', imageData,
          filename: images[i].name, contentType: MediaType('image', 'jpg'));

      Map<String, String> headers = {'Content-Type': 'multipart/form-data'};

      var _response = await http.MultipartRequest(
          'POST',
          Uri.parse(
            "https://churchiest-dump.000webhostapp.com/testQuestionRate.php",
          ));
      _response.headers.addAll(headers);
      _response.fields.addAll({
        "question_id": queID,
        "question_rating": rating.toString(),
        "note": discription,
        "date": DateFormat.yMd().format(DateTime.now()),
        "site_id": siteId,
        "supervisor_id": supervisorID,
        "inserted": "1",
        "isImageInserted": images.isEmpty ? "0" : "1"
      });
      _response.files.add(multipartFile);
      print('Request : ' + _response.toString());
      var jsonResponse = await _response.send();
      print(multipartFile);
      print(jsonResponse.statusCode);
      print(jsonResponse.stream);
      print(jsonResponse.request);
      print(jsonResponse.headers);
    }
     Map<String, String> headers = {'Content-Type': 'multipart/form-data'};

      var _response = await http.MultipartRequest(
          'POST',
          Uri.parse(
            "https://churchiest-dump.000webhostapp.com/testQuestionRate.php",
          ));
      _response.headers.addAll(headers);
      _response.fields.addAll({
        "question_id": queID,
        "question_rating": rating.toString(),
        "note": discription,
        "date": DateFormat.yMd().format(DateTime.now()),
        "site_id": siteId,
        "supervisor_id": supervisorID,
        "inserted": "1",
        "isImageInserted": images.isEmpty ? "0" : "1"
      });
     
      print('Request : ' + _response.toString());
      var jsonResponse = await _response.send();
      print(jsonResponse.statusCode);
  }
4

0 回答 0