gpt4 book ai didi

flutter - strip 读取文件同步 Flutter Web 的图像选择器路径

转载 作者:行者123 更新时间:2023-12-04 07:32:44 24 4
gpt4 key购买 nike

我正在使用 file_picker 包处理 flutter https://pub.dev/packages/file_picker
我读过很多次,因为你不能在网络浏览器上访问路径,你需要使用 bytes 属性,例如

FilePickerResult result = await FilePicker.platform.pickFiles();

if(result != null) {
var path = print(result.files.single.path); // this will return null
var bytes = print(result.files.singe.bytes); // this will return a Uint8List of bytes
} else {
// User canceled the picker
}
但是我必须将我的用户通过网络从他们的设备中选择的图像(对于所有类型的设备)上传到我的 Stripe Connect API,以便他们在注册时拥有经过验证的身份文件。字节 Uint8List 将从 firebase 抛出错误,这是我的代码:
export const uploadIdentityFront = async (uid: any, identityFront: any) => {

const fp = fs.readFileSync(identityFront);

const frontIdentity = await stripe.files.create({
file: {
data: fp,
name: 'identityFront.jpg',
type: 'application/octet-stream',
},
purpose: 'identity_document',
});

await updateId(uid, { frontIdentityFileId: frontIdentity.id })
return frontIdentity;

}
抛出的错误:
[firebase_functions/unknown] TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received an instance of Array
我需要通过文件系统的 readFileSync 属性向图像文档发送 strip 才能执行此操作,但是由于 Flutter Web 无法打印用户选择的图像的路径,我被困在如何解决此问题上

最佳答案

我使用此代码将字节发送到我的服务器,该服务器使用流发送。您可以使用 http 包发送流。

var request = http.MultipartRequest(
'POST',
Uri.parse('_url'),
);


request.files.add(
http.MultipartFile.fromBytes(
'identityFront', //name of field which you receive in api
bytes, // bytes
filename: 'identityFront.jpg', // optional name
//contentType: content, optional media Type
));

request.fields.addEntries([
MapEntry('uid', 'uid_value_in_String_Type'),
]);

await request.send();

关于flutter - strip 读取文件同步 Flutter Web 的图像选择器路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67873250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com