Future<String> uploadImage(File file) async {
String fileName = file.path.split('/').last;
FormData formData = FormData.fromMap({
"file":
await MultipartFile.fromFile(file.path, filename:fileName),
});
response = await dio.post("/info", data: formData);
return response.data['id'];
}
contentType 옵션을 추가하는 내용 포함
Future<dynamic> patchUserProfileImage(dynamic input) async {
print("프로필 사진을 서버에 업로드 합니다.");
var dio = new Dio();
try {
dio.options.contentType = 'multipart/form-data';
dio.options.maxRedirects.isFinite;
dio.options.headers = {'token': token};
var response = await dio.patch(
baseUri + '/users/profileimage',
data: input,
);
print('성공적으로 업로드했습니다');
return response.data;
} catch (e) {
print(e);
}
}
Reference
https://stackoverflow.com/questions/57509972/flutter-dio-how-to-upload-image
Flutter Dio : How to Upload Image?
I'm trying on Postman. And it works I want upload some image to rest-api using Package DIO Package , I'm new for this package (i'm use this package just for CRUD operation) and i'm got problem when
stackoverflow.com
https://dkswnkk.tistory.com/334
[flutter] 서버로 이미지 업로드 하기(Dio, image_picker)
유저 프로필 사진을 변경하거나 리뷰에 올릴 사진을 업로드하기 위해 서버에 사진을 업로드하는 경우가 필요하다. 오늘은 서버로 이미지 파일을 업로드하는 경우를 알아보려고 한다. 그전에 설
dkswnkk.tistory.com
728x90
'Flutter' 카테고리의 다른 글
| [Flutter] number format thousand separator (0) | 2022.05.02 |
|---|---|
| [Flutter] image_picker 사용하기 (0) | 2022.05.02 |
| [Flutter] list add to first (0) | 2022.04.28 |
| [Flutter] restrict textfield input type & setting keyboard type (0) | 2022.04.28 |
| [Flutter] flutter close keyboard on textfield submit(close-hide-keyboard) (0) | 2022.04.28 |