Flex 与 Java 上传ByteArray图片数据

Flex 端的上传代码:

			var urlRequest:URLRequest = new URLRequest("http://127.0.0.1:8080/byteup.action");
				urlRequest.data = byteArray;//需要上传的数据
				urlRequest.contentType = "application/octet-stream";
				urlRequest.method =  URLRequestMethod.POST;

				var urlLoader:URLLoader = new URLLoader();
				urlLoader.dataFormat = URLLoaderDataFormat.BINARY;
				urlLoader.addEventListener(Event.COMPLETE,urlLoader_CompleteHandler);
				urlLoader.load(urlRequest);

 Java 端的接收代码:

		String filePath = "c:/test.png";
        InputStream inputStream = request.getInputStream();
        FileOutputStream outputStream = new FileOutputStream(new File(filePath));
       
		int formlength = request.getContentLength();
		byte[] formcontent = new byte[formlength];
		int totalread = 0;
		int nowread = 0;
		while (totalread < formlength) {
			nowread = inputStream.read(formcontent, totalread, formlength);
			totalread += nowread;
		}

        outputStream.write(formcontent);
        outputStream.flush();
        outputStream.close();
        inputStream.close();

 

你可能感兴趣的:(array)