我尝试使用颤振斩波器发送图像。我尝试以 2 种不同的方式来做,但没有一个工作。
@Post(path: '/photos')
@multipart
Future<Response> postFile(
@Header('token') String token, @PartFile('file') List<int> bytes);
@Post(path: '/photos')
@multipart
Future<Response> postFileOnePiece(
@Header('token') String token,
@Body() Map<String, dynamic> body,
);
sendImageTest() async {
final bytes = (await File(
Provider.of<MyLocalStorage>(context, listen: false)
.temporaryMethodGetFullPathOfFirstPhoto())
.readAsBytes())
.toList();
// ### 1
Provider.of<ApiService>(context, listen: false)
.postFileOnePiece(
Provider.of<Token>(context, listen: false).token,
{"file": bytes});
// ### 2
Provider.of<ApiService>(context, listen: false).postFile(
Provider.of<Token>(context, listen: false).token, bytes);
}
我在 Postman 测试了我的 API,这个设置正在运行: