【发布时间】:2021-05-06 17:08:57
【问题描述】:
我想在向服务器发送 http.MultipartFile 请求后从 Flask API 获取结果。 像这样:
Future<String> upload(List<int> filename, String url) async {
//filename : binary conversion of string
//String url : api address
print("Inside Upload future!");
var request = http.MultipartRequest('POST', Uri.parse(url));
request.files.add(
http.MultipartFile.fromBytes('file', filename, filename: 'files.txt'));
print("Sending Request!");
http.Response response = await http.Response.fromStream(await request.send());
print("request sent! now returning");
var rtr = response.body;
return rtr;
}
但问题是它不返回,执行后的输出是 The print after await is not executed 为什么??:
Inside Upload future!
Sending Request!
我正在向 Flask API 发送一个字符串,例如: 它工作正常,它正在接收一个字符串,然后用相同的字符串进行一些修改。
@app.route('/test_api', methods=['GET', 'POST'])
def test_api():
uploaded_file = request.files['file']
file_content = uploaded_file.read().splitlines()
uploaded_file.seek(0)
file_pretty = uploaded_file.read()
a = runkey(file_pretty)
//takes string agrument and returns manipulated string
uploaded_file.seek(0)
filename = secure_filename(uploaded_file.filename)
resp = make_response(a)
resp.headers['Content-Type'] = 'text/plain;charset=UTF-8'
n = filename
resp.headers['Content-Disposition'] = 'attachment;filename='+'n'
return resp ```
【问题讨论】:
标签: flutter dart asynchronous