Changes between Initial Version and Version 1 of API/BBS/Upload-Picture


Ignore:
Timestamp:
04/20/2011 09:59:50 AM (15 years ago)
Author:
lee
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • API/BBS/Upload-Picture

    v1 v1  
     1[[TOC]] 
     2 
     3== Java Demo == 
     4 
     5{{{ 
     6#!java 
     7import org.apache.http.util.EntityUtils; 
     8import java.io.IOException; 
     9import org.apache.http.HttpResponse; 
     10import org.apache.http.entity.mime.HttpMultipartMode; 
     11import org.apache.http.entity.mime.MultipartEntity; 
     12import java.io.File; 
     13import org.apache.http.client.methods.HttpPost; 
     14import org.apache.http.entity.mime.content.FileBody; 
     15import org.apache.http.impl.client.DefaultHttpClient; 
     16 
     17/* 
     18{ 
     19    "retCode":0, 
     20    "tid":1035162 
     21    "files": 
     22    [ 
     23        { 
     24            "fileSize":71007, 
     25            "height":480, 
     26            "rid":1510777, 
     27            "width":320, 
     28            "fileName":"1035162_1303205757907.jpg", 
     29            "audit":"New", 
     30            "orgFileName":"m.jpg", 
     31            "isorg":1, 
     32            "url":"http://test745.pcauto.com.cn:9192/upcfiles/yidong/1104/19/c0/1035162_1303205757907.jpg" 
     33        } 
     34    ], 
     35} 
     36 
     37*/ 
     38 
     39/* 
     40状态码                                 值     备注 
     41========================================================== 
     42UPC_OK                                 0;         成功 
     43UPC_NO_TRANSACTION_SPECIFIED         1;         事务编码未指定 
     44UPC_SPECIFIED_TRANSACTION_NOT_FOUND     2;         事务编码不存在 
     45UPC_CREATE_TRANSACTION_FAILED         3;         创建事务失败 
     46UPC_INVALID_PARAMETERS                 4;         非法的参数 
     47UPC_UPLOAD_FAILED                     5;         上传失败 
     48UPC_PROCESS_FAILED                     6;         处理失败 
     49UPC_TRANSACTION_CLOSED                 7;         事务已关闭 
     50UPC_DEL_TRANSACTION_FAILED             8;         删除事务失败 
     51UPC_DEL_RESOURCE_FAILED                 9;         资源删除失败 
     52UPC_NO_RESOURCE_SPECIFIED             10;         未指定资源 
     53UPC_UPDATE_RESOURCE_FAILED             11;         资源更新失败 
     54UPC_USER_NOT_LOGON                     12;         用户未登录 
     55UPC_INVALID_STATE                     13;         非法的状态 
     56UPC_SIZE_LIMITED_EXCEED                 14;         文件大小超出规定 
     57UPC_NO_APPLICATION_SPECIFIED         15;         未指定应用编码 
     58UPC_COMMIT_FAILED                     16;     
     59UPC_SPECIFIED_APPLICATION_NOT_FOUND     17;     
     60UPC_INVALID_COMMAND                     18;     
     61UPC_INVALID_USER                     19;     
     62UPC_ERROR_OTHERS                     100;     未知错误 
     63*/ 
     64 
     65class TestUpload { 
     66 
     67    public static void main(String[] args) { 
     68 
     69        testUpload(); 
     70        
     71    } 
     72    
     73 
     74    public static void testUpload() throws IOException { 
     75        DefaultHttpClient hc = new DefaultHttpClient(); 
     76 
     77        // http://upc.pcauto.com.cn/upload_quick.jsp 正式环境使用 
     78        HttpPost post = 
     79                new HttpPost( 
     80                "http://test745.pconline.com.cn:9192/uploadcenter/upload_quick.jsp?application=yidong"); 
     81 
     82        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 
     83 
     84        reqEntity.addPart( 
     85                "file",     // 上传form的input标签名称 
     86                new FileBody(new File("C:\\data\\path0\\m.jpg"))); 
     87 
     88        // 测试登录Cookie,正式环境不需要用, 
     89        // 测试环境获得cookie方法:http://test232.pconline.com.cn:7003/passport2/ 测试环境登录:ddd/123456 
     90        post.setHeader("Cookie", "common_session_id1=1E206769DF2AC93174ACCA2C04D86B60B43FD0351F1331A8"); 
     91 
     92        post.setEntity(reqEntity); 
     93 
     94        HttpResponse response = hc.execute(post); 
     95 
     96        System.out.println(response.getStatusLine()); 
     97 
     98        System.out.println(EntityUtils.toString(response.getEntity())); 
     99 
     100/* 
     101{ 
     102    "retCode":0, 
     103    "tid":1035162 
     104    "files": 
     105    [ 
     106        { 
     107            "fileSize":71007, 
     108            "height":480, 
     109            "rid":1510777, 
     110            "width":320, 
     111            "fileName":"1035162_1303205757907.jpg", 
     112            "audit":"New", 
     113            "orgFileName":"m.jpg", 
     114            "isorg":1, 
     115            "url":"http://test745.pcauto.com.cn:9192/upcfiles/yidong/1104/19/c0/1035162_1303205757907.jpg" 
     116        } 
     117    ], 
     118} 
     119 
     120*/ 
     121 
     122        post.abort(); 
     123 
     124    } 
     125 
     126} 
     127}}}