【发布时间】:2019-02-03 22:07:39
【问题描述】:
我正在尝试使用以下功能上传图片,一切正常,只是我想在帖子中发送图片,而当我尝试让图片一无所获时
这是调用 API
Future getUploadImg(access_token,File _image) async {
print("Image: $_image");
String apiUrl = '$_apiUrl/user/upload-profile-image';
final length = await _image.length();
final request = new http.MultipartRequest('POST', Uri.parse(apiUrl));
request.headers['Accesstoken'] = "Bearer $access_token";
request.files.add(new http.MultipartFile('imagefile',_image.openRead(), length));
http.Response response = await http.Response.fromStream(await request.send());
print("Result: ${response.body}");
return json.decode(response.body);
}
我传递给服务器的文件是:
File: '/storage/emulated/0/Android/data/com.dotsquares.ecomhybrid/files/Pictures/c5df03f7-097d-47ca-a3c5-f896b2a38c086982492957343724084.jpg'
【问题讨论】:
-
您能解释一下您面临的问题吗?
-
当我使用 API 参数传递图像时,没有进入 POST 或 File 方法。
标签: php image api flutter image-uploading