【发布时间】:2021-11-11 02:48:37
【问题描述】:
var request = http.MultipartRequest('post', Uri.parse(TravelingUrl.testAddress + '/test'));
request.fields['title'] = createDiary.value.title as String;
request.fields['tag_list'] = createDiary.value.tagList.toString();
request.fields['date'] = createDiary.value.date.toString();
for (var i = 0; i < createDiary.value.pages!.length; i++) {
Pages _tempPage = createDiary.value.pages![i];
request.fields['pages[$i][order]'] = jsonEncode(_tempPage.order);
request.fields['pages[$i][description]'] =
jsonEncode(_tempPage.description);
for (var ii = 0; ii < _tempPage.images!.length; ii++) {
request.files.add(await http.MultipartFile.fromPath(
'pages[$i][images]', _tempPage.images![ii]));
}
}
var response = await request.send();
上面的代码是flutter向golang传输数据的逻辑。
我想在 golang 中使用从颤振中接收到的数据。
我在 golang 中定义了这样的结构
type _pages struct {
Order uint `json:"order"`
Description string `json:"description"`
Images []multipart.File `json:"images"`
}
type _tags struct {
TagId uint `json:"id"`
TagName string `json:"tag_name"`
}
type _getData struct {
Title string `json:"title"`
Date string `json:"date"`
Location string `json:"location"`
Address string `json:"address"`
_tags
_pages
}
我对golang不熟悉,请帮忙,我能看一个简单的获取数据并使用它的例子吗?
数组变量中有文件数据,我想接收数据并将这个文件数据保存到s3。
【问题讨论】:
-
fmt.Print(r.FormValue("title")) 工作正常,但 fmt.Print(r.FormValue("pages")) 不起作用,
-
我不知道页面上有多少项目
-
这是大多数开发者使用的方式吗?
标签: amazon-web-services flutter dart go