flutter - Flutter:将 Base64 String 图像 url 转换为 File 并在 FileImage 或相关小部件中使用
问题描述
我已经尝试过这种方式,并使用它,FileImage
但还没有找到一个集结点
Uint8List bytes = base64.decode(imageBase64);
File file = File.fromRawPath(bytes);
imageBase64
是已经编码的图片url。
这件事的重点是,我想在FileImage
或其他小部件图像文件中使用它,但我不希望将此图像保存到设备并将此文件上传到附件文件 Rest API
谁能帮我。
解决方案
If what you want to do once you have the bytes is to show the image, then you can use Image.memory
.
var imageWidget = Image.memory(bytes);
OTOH If you're trying to upload the image, you don't need to convert it into file. You can use bytes directly assuming you can't upload it using base64 enconding. Package http
import 'package:http/http.dart';
...
//create multipart using filepath, string or bytes
MultipartFile multipartFile = MultipartFile.fromBytes(
'file',
byteData,
filename: fileName,
);
//add multipart to request
request.files.add(multipartFile);
var response = await request.send();
推荐阅读
- python - 为什么我的字典理解只改变第一个键/值
- vue.js - 如何将 Leaflet.js 连接到 Vue.js
- javascript - 异步 JS 脚本正在加载分离浏览器状态
- modelica - Modelica 三次多项式的平滑阶
- javascript - CryptoJs AES 解密格式错误的 UTF-8 数据
- django - 错误 manage.py 转储数据 > db.json
- c# - 每个事件完成后如何在自动状态机中发布事件?
- python - ODOO 14,如何通过模板中的rest api渲染另一个模板?
- matlab - MATLAB,fitcknn 使用梅尔频率倒谱系数 (MFCC)
- ruby-on-rails - OmniAuth:secret 或 digest 到底是什么意思?如何获得?