MultipartRequest dosen't work
- Dominant language
- Dart
- Stars
- 1.1k
- Forks
- 419
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 8
Description
I'm trying to upload a image file using MultipartRequest, it dosen't seem to work. I checked using postman, api seem to work fine. Not sure whats wrong with the MultipartRequest.
My Code:
```dart
Future> uploadImage(SubmitData data, String token) async {
String path = data.imageFile;
if (Platform.isIOS) {
path = Uri.parse(path).toFilePath();
}
final Uri uri = Uri.parse(_getUrl(path: '/api/v1/upload'));
final MultipartRequest request = MultipartRequest('POST', uri);
request.headers['Authorization'] = token;
request.fields['id'] = data.id.toString();
final MultipartFile multipartFile =
await MultipartFile.fromPath('image', path);
request.files.add(multipartFile);
final StreamedResponse response = await request.send();
final String res = await response.stream.transform(utf8.decoder).join();
final List temp = json.decode(res)['images'];
return temp.cast();
}
```
I'm getting an error:
Sometimes
`SocketException: Write failed (OS Error: Broken pipe, errno = 32),`
or
`SocketException: Connection reset by peer (OS Error: Broken pipe, errno = 54),`
not sure why this would ever happen.
Contributor guide
Research direction
Start by reproducing the upload using the shown MultipartRequest code, including MultipartFile.fromPath and request.send(), and capture the request and server response around the broken-pipe errors. The issue is done when the cause of the intermittent connection reset is identified and a verified fix or clear reproduction guidance is provided.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100