【发布时间】:2021-05-05 08:22:43
【问题描述】:
我在移动应用程序中使用 WooCommerce Rest Api。现在我想更改个人资料图片,但我不知道如何通过 WooCommerce Rest Api 将图片上传到 Wordpress 网站,我已经尝试过了,但它显示 HTTP 错误 403:
Future<String> uploadImage(File imageFile) async {
final StringBuffer url =
new StringBuffer("$serverName/wp-json/wp/v2/media");
Dio dio = new Dio();
try {
FormData formData = FormData.fromMap(
{"file": await MultipartFile.fromFile(imageFile.path)},
);
dio.options.headers["Authorization"] = "Bearer $token";
var response = await dio.post(
url.toString(),
data: formData,
);
var respon = response.data;
return respon["url"];
} on DioError catch (e) {
print(e.message);
} catch (e) {
print(e);
}
}
谁能帮帮我?
【问题讨论】:
标签: wordpress flutter woocommerce file-upload woocommerce-rest-api