Flutter upload document : file key is missing in payload - Stack Overflow

时间: 2025-01-06 admin 业界

Future<ApiResponse> apiPostFileSecured( Uri uri, String fieldKey, Map<String, dynamic> jsonBody, T Function(Map<String, dynamic>) fromJson, Stream<List> stream, int length) async { final headers = await createMultiPartAuthHeader(); print(headers); if (headers == null) { return ApiResponse(body: null, code: 401); } var request = http.MultipartRequest('POST', uri); print(request); //request.files.add(await MultipartFile.fromBytes("file", filePath!.toList())); request.files.add(await http.MultipartFile('file', stream,length, contentType: new MediaType('document','pdf'), filename: "AWShostingdetails.pdf"));
sleep(Duration(seconds: 20)); request.headers.addAll(headers); request.fields[fieldKey] = jsonEncode(jsonBody); print("apiPostFileSecured +++++++++++++"); var streamResponse = await request.send(); print("apiPostFileSecured ************"); var response = await http.Response.fromStream(streamResponse); return parseResponse(response, fromJson); }

Below is my Payload: documentInfo: {"userDocumentDetailId":null,"documentName":"PAN Document","documentType":"PAN_CARD","fileDetailId":null,"fileType":"pdf","file":null,"documentVerified":null,"userDetailId":1,"fileName":"AWShostingdetails.pdf"}

In above payload data file key is missing. Please help me understand the issue.

最新文章