Flutter开发都两年了。最新需求通过OSS基于POST上传文件。
直接上代码:
//获取上传Token
void _uploadImgToosm(File imagFile) async {
//第一步每次上传之前请求oss_token来获取上传必须参数。
var imgFileName = imagFile.path.split("/")[imagFile.path.split("/").length - 1];
Map<String, String> header = new Map();
Map<String, String> parames = new Map();
parames["fileName"] = imgFileName; //
parames["fileType"] = "image";
String jsons = json.encode(parames);
MyNetUtil.instance.postData("/mjs/api/v1/platform/oss_token", (value) async {
InformationBeanEntity informationBeanData = InformationBeanEntity().fromJson(value);
Dio dio = new Dio();
dio.options.responseType = ResponseType.plain;
dio.options.contentType ="multipart/form-data";
String host = informationBeanData.data.host;
var imgFileName = imagFile.path.split("/")[imagFile.path.s