英文:
I don't know how to transfer files in flutter
问题
当您在Flutter中选择一张图片时,您会得到这些数据,我想将这些数据发送到Golang服务器,但我不知道如何做。我正在使用http包,而不是使用dio。
/private/var/mobile/Containers/Data/Application/EE757681-C1B8-4FCC-BAB2-9A685A29E4A5/tmp/image_picker_06D171DF-30FA-4C15-908E-7FE4AD379DD9-23404-000012F0F6E55F99.png
我甚至不知道如何从Golang获取文件并将其保存到S3,但首先我想能够将其从Flutter传输到Golang。
我该如何在Golang服务器上处理这个图片?请帮忙。
英文:
When I select a picture in flutter, I get this data, I want to send this data to the golang server, but I don't know how. I am using http package without using dio.
/private/var/mobile/Containers/Data/Application/EE757681-C1B8-4FCC-BAB2-9A685A29E4A5/tmp/image_picker_06D171DF-30FA-4C15-908E-7FE4AD379DD9-23404-000012F0F6E55F99.png
I don't even know how to get a file from golang and save it to s3, but first I want to be able to transfer it from flutter to golang.
How can I control the image on the golang server? Please help
答案1
得分: 1
你可以使用MultipartRequest类来实现这个目的,正如http包的文档中所说。
var uri = Uri.https('example.com', 'create');
var request = http.MultipartRequest('POST', uri)
..fields['user'] = 'nweiz@google.com'
..files.add(await http.MultipartFile.fromPath(
'package', 'build/package.tar.gz',
contentType: MediaType('application', 'x-tar')));
var response = await request.send();
if (response.statusCode == 200) print('Uploaded!');
英文:
You can use MultipartRequest class to that purpose as it say in http package documentation
var uri = Uri.https('example.com', 'create');
var request = http.MultipartRequest('POST', uri)
..fields['user'] = 'nweiz@google.com'
..files.add(await http.MultipartFile.fromPath(
'package', 'build/package.tar.gz',
contentType: MediaType('application', 'x-tar')));
var response = await request.send();
if (response.statusCode == 200) print('Uploaded!');
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论