作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
FormData formData = FormData.fromMap({
"image": await MultipartFile.fromFile(image.path,
filename: "test.${image.path.split(".").last}")
});
var dio = Dio();
var res = await dio.post(
"$url/users/profile/image/add",
data: formData),
);
{success: true, profile_picture: /files/images/users/40.png}
最佳答案
要从URL下载图像,请使用image_downloader软件包,如下所示:
try {
// Saved with this method.
var imageId = await ImageDownloader.downloadImage("https://raw.githubusercontent.com/wiki/ko2ic/image_downloader/images/flutter.png");
if (imageId == null) {
return;
}
// Below is a method of obtaining saved image information.
var fileName = await ImageDownloader.findName(imageId);
var path = await ImageDownloader.findPath(imageId);
var size = await ImageDownloader.findByteSize(imageId);
var mimeType = await ImageDownloader.findMimeType(imageId);
} on PlatformException catch (error) {
print(error);
}
import 'package:path/path.dart';
import 'package:async/async.dart';
import 'dart:io';
import 'package:http/http.dart' as http;
Upload(File imageFile) async {
var stream = new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
var length = await imageFile.length();
var uri = Uri.parse(uploadURL);
var request = new http.MultipartRequest("POST", uri);
var multipartFile = new http.MultipartFile('file', stream, length,
filename: basename(imageFile.path));
//contentType: new MediaType('image', 'png'));
request.files.add(multipartFile);
var response = await request.send();
print(response.statusCode);
response.stream.transform(utf8.decoder).listen((value) {
print(value);
});
}
Image.network(
imageUrl,
)
关于flutter - 如何在Flutter中显示来自String Url的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59598207/
我是一名优秀的程序员,十分优秀!