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

Upload file audio and video not working #221

Closed
phuquy2114 opened this issue Jan 5, 2019 · 2 comments
Closed

Upload file audio and video not working #221

phuquy2114 opened this issue Jan 5, 2019 · 2 comments

Comments

@phuquy2114
Copy link

void _submitApplyGuider(BuildContext context, viewModel) async {
var token = await Helpers.getSharedPrefs('token');
Map<String, String> headers = {
"Authorization": "Bearer $token",
"Content-Type": "multipart/form-data"
};
var uri = Uri.parse(settings.baseUrl + "/update-introduce");
print(uri);
var request = new http.MultipartRequest("POST", uri);
// add header
request.headers.addAll(headers);

request.fields['bio'] = "Test fields"

// var streamAudio = new http.ByteStream(
// DelegatingStream.typed(_formData['audio_file'].openRead()));
// var streamVideo = new http.ByteStream(
// DelegatingStream.typed(_formData['movie_file'].openRead()));
// var lengthAudio = await _formData['audio_file'].length();
// var lengthVideo = await _formData['movie_file'].length();
//
// var multipartFile = new http.MultipartFile(
// 'audio_file', streamAudio, lengthAudio,
// filename: basename(_formData['audio_file'].path));
// var multipartFileVideo = new http.MultipartFile(
// 'movie_file', streamVideo, lengthVideo,
// filename: basename(_formData['movie_file'].path));

// request.files.add(multipartFile);
// request.files.add(multipartFileVideo);

request.files.add(await http.MultipartFile.fromPath(
    'audio_file', _formData['audio_file'].path));
request.files.add(await http.MultipartFile.fromPath(
    'movie_file', _formData['movie_file'].path));

StreamedResponse response = await request.send().then((response) {
  print("successful");
  print(response.toString());
  if (response.statusCode == 200)
    Helpers.appDialog(context, "Update successfully !", 'success');
});

print(response.toString());
response.stream.transform(utf8.decoder).listen((value) {
  print(value);
});

}

I don't know when I upload file It's the error.

@thosakwe
Copy link

I think you should maybe paste the error message and stack trace, so it's easier to diagnose what's going on.

@natebosch
Copy link
Member

Closing since we'll be unable to help without more details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants