我试图将带有Cookie的个人资料图片文件上传到服务器。但是我不知道如何上传。
这是我的代码:
_submit() async {
Api.updateUserProfileImage(
context,
_image,
await Provider.of<AccountState>(context, listen: false)
.storage
.read(key: "cookie"),
);
}
static void updateUserProfileImage(
BuildContext context, File image, String cookie) async {}
var request = http.MultipartRequest(
"POST",
Uri.parse(
"YourAPILINK",
),
);
Map<String, String> headers = {
'Content-Type': 'multipart/form-data',
'token': token
};
request.headers['token'] = token;
request.headers["Content-Type"]='multipart/form-data';
request.fields["name"] = "hardik";
request.fields["email"] = "[email protected]";
request.fields["mobile"] = "00000000";
request.fields["address"] = "afa";
request.fields["city"] = "fsf";
if (image != null) {
print(image.path.split(".").last);
request.files.add(
http.MultipartFile.fromBytes(
"avatar",
image.readAsBytesSync(),
filename: "test.${image.path.split(".").last}",
contentType: MediaType(
"image", "${image.path.split(".").last}"),
),
);
}
request.fields["reminder_interval"] = "1";
request.send().then((onValue) {
print(onValue.statusCode);
print(onValue.headers);
print(onValue.contentLength);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句