ここで送信されたデータはデータベース内の 1 つのテーブルに挿入され、画像は別のテーブルに挿入されます。ユーザーは、画像セレクターの数に要求を送信します。そうしないと、いくつの画像が選択されても、1 つの画像だけがテーブルに挿入されます。
選択したすべての画像テーブルをテーブルに挿入し、他のデータを一度だけ挿入することはできますか?
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);
}