01 package {
02 import com.adobe.images.JPGEncoder;
03 import flash.display.Sprite;
04 import flash.events.Event;
05 import flash.events.IOErrorEvent;
06 import flash.net.URLLoader;
07 import flash.net.URLRequest;
08 import flash.net.URLRequestMethod;
09 import flash.text.TextField;
10 import flash.utils.ByteArray;
11 import mx.core.BitmapAsset;
12
13 [SWC(width='400',height='400',backgroundColor='0x4c4c4c',frameRate='30')]
14 public class Base extends Sprite
15 {
16 [Embed(source="../1.jpg")] // same png / gif files
17 private var Photo:Class ;
18
19 private var url:String ="http://localhost:8080/PicSample/aaa" ;
20 private var _loader:URLLoader = newURLLoader();;
21 private var reposeTxt:TextField;
22
23 public function Base()
24 {
25 reposeTxt = new TextField();
26 addChild(reposeTxt);
27 reposeTxt.text = "waiting....";
28
29 var photo:BitmapAsset = new Photo();
30 var urlRequest:URLRequest = newURLRequest(url);
31
32 var JPG:JPGEncoder = new JPGEncoder(70);
33 var bary:ByteArray =JPG.encode(photo.bitmapData);
34 urlRequest.data=bary;
35 urlRequest.method=URLRequestMethod.POST;
36 urlRequest.contentType ="application/octet-stream";
37 _loader.addEventListener(Event.COMPLETE,completeHandler);
38 _loader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
39 _loader.load(urlRequest);
40
41 }
42 private functioncompleteHandler(evt:Event):void {
43 reposeTxt.text = "成功";
44 }
45 private functionioErrorHandler(evt:IOErrorEvent):void {
46 reposeTxt.text = "失败";
47 }
48 }
49 }
01 @Override
02 protected void doPost(HttpServletRequest request,HttpServletResponse response)
03 throws ServletException, IOException {
04
05 ServletInputStream in =request.getInputStream();
06 OutputStream outStream = newFileOutputStream("e:/m34.jpg");
07 int b =0;
08 while(b!= -1)
09 {
10 in.available();
11 b = in.read();
12 if(b!= -1)
13 outStream.write(b);
14 }
15 outStream.close();
16 }