Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The request was rejected because no multipart boundary was found #355

Closed
ThanhPhungTien opened this issue Jan 2, 2020 · 3 comments
Closed
Labels
closed-duplicate Closed in favor of an existing report

Comments

@ThanhPhungTien
Copy link

The request was rejected because no multipart boundary was found

 Future<StreamedResponse> uploadImage(File file) async {
    String _url = URLConstant.baseURL + this.url;
    final headers = Map<String, String>();
    headers[Constant.contentType] = 'multipart/form-data';
    headers[Constant.headerAPI] = prefs.getString(Constant.token).toString();
    var uri = Uri.parse(_url);
    var stream = ByteStream(DelegatingStream.typed(file.openRead()));
    var length = await file.length();
    var request = MultipartRequest("POST", uri);
    String fileType = file.path.substring(file.path.lastIndexOf('.')+1,file.path.length);
    var multipartFile = MultipartFile(
      'file',
      stream,
      length,
      filename: basename(file.path),
      contentType: MediaType('application',fileType),
    );
    request.files.add(multipartFile);
    request.headers.addAll(headers);
    print('Header' + request.headers.toString());
    var response = await request.send();
    print(response.statusCode);
    return response;
  }

Env

  • Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.14.6 18G103, locale en-VN)
  • Flutter version 1.12.13+hotfix.5
  • Framework revision 27321ebbad (3 weeks ago), 2019-12-10 18:15:01 -0800
  • Engine revision 2994f7e1e6
  • Dart version 2.7.0
  • Http: 0.12.0+3
@natebosch
Copy link
Member

What is the value of Constant.contentType? Can you try not setting that header? It is already set by the request. I would expect this to be overridden automatically, but that might work if the key you are using has different capitalization or something.

headers['content-type'] = 'multipart/form-data; boundary=$boundary';

@ThanhPhungTien
Copy link
Author

The value of Constant.contentType is 'Content-Type'. Previously I used version 0.11.3 + 17 is still normal. But when upgrading to version 0.12.0 + 3, the above error appears.

@natebosch
Copy link
Member

I confirmed that we had a regression here. Tracking at #351

I'll close this one as a duplicate. In the mead time, it still won't be a good idea to set your own content type header.

@natebosch natebosch added closed-duplicate Closed in favor of an existing report and removed need-info labels Jan 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report
Projects
None yet
Development

No branches or pull requests

2 participants