从服务器请求文件流工具类,SpringBoot我想获取图片流,然后将图片流的数据传到服务器上...

我想获取图片流,然后将图片流的数据传到服务器上

这行好像是获取图片流的,但是这个buffers我怎么传递给服务器

我想把buffers作为参数传给口,不知道怎么实现?ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);

1、这段代码是跑在本地电脑上的

2、有个远程服务端,我希望跑这段代码时,可以将图片流传给远程的服务器

3、我希望将图片流传给远程服务器的接口for(int i=0;i

{

if(strItsPlateResult.struPicInfo[i].dwDataLen>0)

{

SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");

String newName = sf.format(new Date());

FileOutputStream fout;

try {

// String filename = ".\\pic\\"+ new String(pAlarmer.sDeviceIP).trim() + "_"

// + newName+"_type["+strItsPlateResult.struPicInfo[i].byType+"]_ItsPlate.jpg";

String filename = "D:\\ScenePics\\Plate20210416165034669.jpg";

fout = new FileOutputStream(filename);

//将字节写入文件

long offset = 0;

ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);

System.out.println("buffers == " + buffers);

byte [] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen];

System.out.println("bytes == " + bytes);

buffers.rewind();

buffers.get(bytes);

fout.write(bytes);

fout.close();

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

获取图片数据流接口/**

* 从输入流中获取数据

*

* 输入流

* @return

* @throws Exception

*/

@ApiOperation("获取图片二进制流")

@RequestMapping(value="/v1/bulldozer-info/inputStream", method={ RequestMethod.POST })

public static byte[] readInputStream(HttpServletRequest request, HttpServletResponse response) throws Exception {

String fileName = request.getParameter("fileName");

log.info("filename:"+fileName);

// String fileName ="shafei.xls";

// String fileFullPath = "C:/Users/Dell/Desktop/print/test/" + fileName;

String fileFullPath = "/Users/shanguangqing/Desktop/company20210122/bulldozer-admin-java/abbott-cloud-core/target/" + fileName;

InputStream input = null;

FileOutputStream fos = null;

try {

input = request.getInputStream();

File file = new File("/Users/shanguangqing/Desktop/company20210122/bulldozer-admin-java/abbott-cloud-core/target/");

if(!file.exists()){

file.mkdirs();

}

fos = new FileOutputStream(fileFullPath);

int size = 0;

byte[] buffer = new byte[1024];

while ((size = input.read(buffer,0,1024)) != -1) {

fos.write(buffer, 0, size);

}

//响应信息 json字符串格式

Map responseMap = new HashMap();

responseMap.put("flag", true);

//生成响应的json字符串

String jsonResponse = JSONObject.toJSONString(responseMap);

// sendResponse(jsonResponse,response);

} catch (IOException e) {

//响应信息 json字符串格式

Map responseMap = new HashMap();

responseMap.put("flag", false);

responseMap.put("errorMsg", e.getMessage());

String jsonResponse = JSONObject.toJSONString(responseMap);

// sendResponse(jsonResponse,response);

} finally{

if(input != null){

input.close();

}

if(fos != null){

fos.close();

}

}

return null;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值