首先,资源文件需保存在类路径下,这样ClassLoader才能够找到,
其次,资源文件路径需要项目路径,
最后,推荐返回IO流的操作形式
public static BufferedReader getReader(String name) { // maven工程修改词典加载方式 InputStream in = this.class.getResourceAsStream("/" + name); try { return new BufferedReader(new InputStreamReader(in, "UTF-8")); } catch (UnsupportedEncodingException e) { logger.warn("不支持的编码", e); } return null; } public static InputStream getInputStream(String name) { // maven工程修改词典加载方式 InputStream in = this.class.getResourceAsStream("/" + name); return in; }
from urllib3 import encode_multipart_formdata
import requests
data = {}
header = {}
data['file'] = ('t4.png', open('/home/lab/rosetta/srfPicTextRecog-online/test/t4.png', 'rb').read())
encode_data = encode_multipart_formdata(data)
data = encode_data[0]
header['Content-Type'] = encode_data[1]
url = 'http://172.18.28.100:58088/image/file'
r = requests.post(url, headers=header, data=data)
print(r.content)