首页 > 其他分享 >文件图片上传

文件图片上传

时间:2022-11-29 14:36:28浏览次数:41  
标签:文件 text image sdcard new 上传 resp 图片


[java] ​​ view plain​​ ​​copy​​



  1. package
  2.   
  3. import
  4. import
  5. import
  6. import
  7.   
  8. import
  9. import
  10. import
  11. import
  12. import
  13. import
  14. import
  15. import
  16. import
  17. import
  18.   
  19. import
  20. import
  21. import
  22. import
  23. import
  24.   
  25. public class MainActivity extends Activity implements
  26. private
  27.   
  28. @Override
  29. protected void
  30. super.onCreate(savedInstanceState);  
  31.         setContentView(R.layout.main);  
  32.         uploadBtn = (Button) findViewById(R.id.main_btn);  
  33. this);  
  34.     }  
  35.   
  36. @Override
  37. public void
  38. if
  39. final List<String> list = new
  40. "/storage/sdcard0/updateAdtech/orgpic/1.png");  
  41. "/storage/sdcard0/updateAdtech/orgpic/2.png");  
  42. new
  43. public void
  44. "just test", "sdcard/image/a.amr", list);  
  45.                 };  
  46.             }.start();  
  47.         }  
  48.     }  
  49.   
  50. /**
  51.      * 
  52.      * @Description: 上传方法
  53.      * 
  54.      * @param audioPath
  55.      *            上传音频文件地址 例:sdcard/image/a.amr
  56.      * 
  57.      * @param text
  58.      *            上传文本的值
  59.      * 
  60.      * @param imageUrlList
  61.      *            图片地址的集合 例:sdcard/image/a.jpg, sdcard/image/b.jpg
  62.      * 
  63.      * @return void
  64.      */
  65.   
  66. private synchronized void
  67.             List<String> imageUrlList) {  
  68. try
  69. new
  70. int
  71. for (int i = 0; i < size; i++) {  
  72.                 filePath[i] = imageUrlList.get(i);  
  73.             }  
  74. // 链接超时,请求超时设置
  75. new
  76. 10 * 1000);  
  77. 10 * 1000);  
  78.   
  79. // 请求参数设置
  80. new
  81. new
  82. "http://service.ireadhome.com/api/Upload/Image");  
  83. new
  84. // 上传 文本, 转换编码为utf-8 其中"text" 为字段名,
  85. // 后边new StringBody(text,
  86. // Charset.forName(CHARSET))为参数值,其实就是正常的值转换成utf-8的编码格式
  87. "text",  
  88. new StringBody(text, Charset.forName("UTF-8")));  
  89. // 上传多个文本可以在此处添加上边代码,修改字段和值即可
  90.   
  91. // 上传音频文件
  92. "audio",  
  93. new FileBody(new File(audioPath), "audio/*"));  
  94. // 上传图片
  95. for
  96. "fileimg", new FileBody(new File(p), "image/*"));  
  97.             }  
  98.             post.setEntity(entity);  
  99.             HttpResponse resp = client.execute(post);  
  100. // 获取回调值
  101. "Response:"
  102.                     + EntityUtils.toString(resp.getEntity()));  
  103. "StatusCode:"
  104.                     + resp.getStatusLine().getStatusCode());  
  105. catch
  106.             e.printStackTrace();  
  107.         }  
  108.     }  
  109. }  



标签:文件,text,image,sdcard,new,上传,resp,图片
From: https://blog.51cto.com/u_13657808/5894974

相关文章