uploadFileParentChild static method

Future<String> uploadFileParentChild(
  1. File file,
  2. String tableName,
  3. int id,
  4. String fieldName,
  5. String parentTableName,
  6. int parentId, {
  7. String fileName = '',
})

Implementation

static Future<String> uploadFileParentChild(
  File file,
  String tableName,
  int id,
  String fieldName,
  String parentTableName,
  int parentId, {
  String fileName = '',
}) async {
  //create multipart request for POST or PATCH method
  if (fileName == '') {
    fileName = getFileName(file.path);
  }
  var request = http.MultipartRequest(
      'POST', Uri.parse('${Common.url_host}/File/UploadImageFieldNameChild'));
  //add text fields
  request.fields['tableName'] = tableName;
  request.fields['id'] = id.toString();
  request.fields['fieldName'] = fieldName;
  request.fields['parentTableName'] = parentTableName;
  request.fields['parentId'] = parentId.toString();
  request.fields['fileName'] = fileName;
  request.fields['uid'] = Common.uid.toString();
  request.fields['mode'] = 'create_small';
  //create multipart using filepath, string or bytes
  var pic = await http.MultipartFile.fromPath('file', file.path);
  //add multipart to request
  request.files.add(pic);
  var response = await request.send();

  //Get the response from the server
  var responseData = await response.stream.toBytes();
  var responseString = String.fromCharCodes(responseData);
  return responseString;
}