개발/Flutter
MultipartRequest의 response 처리
leebera_
2022. 6. 28. 20:57
MultipartRequest는 일반적인 get, post 함수로 통신하면 결과로 Response타입의 데이터를 주는 것과 달리 결과로 StreamedResponse타입의 데이터를 뱉는다.
이를 Response클래스 내의 fromStream함수를 이용해 StreamedResponse를 Response로 변경하면 get, post 등의 결과처럼 처리 가능하다.
// request -> MultipartRequest request;
final streamedResponse = await request.send();
final result = await http.Response.fromStream(streamedResponse);
참고
How to get response body with request.send() in dart
I'm doing an api request uploading an image with var request = new http.MultipartRequest("POST", uri); var response = await request.send() in dart using flutter. I can then check the response cod...
stackoverflow.com