Android 는 서버 에 사진 을, android - async - http 는 서버 에 사진 을 업로드
                                            
 2920 단어  Android
                    
도구 다운로드 주소:https://github.com/loopj/android-async-http/tree/1.4.6/releases
홈 페이지 에 도 소개 가 있다.http://loopj.com/android-async-http/
Android 원본 세 션:
private void uploadImage()
	{
		//      
		String url="http://172.16.3.129:8082/jd-web/FileUpload.do?cmd=uploadFiles";
		try {
			String imageUrl="/storage/sdcard0/upload/yellow.jpg";
			RequestParams params=new RequestParams();
			//params.add("cmd","uploadFiles");//   
			//params.add("albumId","93345");//  ID
			//     ,           ,         ,  put             ,      ,
			//              ,          key   ,      ,       ,
			//     "application/octet-stream",     ,             。
			//params.put("image", new File(imageUrl),"application/octet-stream");
			params.put("profile_picture", new File(imageUrl));
			HttpUtil.post(url,params, uploadResponseHander());
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			tvShowLog.setText("      ");
		}
	}
	/**
	 *     
	 * @return
	 */
	private AsyncHttpResponseHandler uploadResponseHander()
	{
		return new AsyncHttpResponseHandler()
		{
			@Override
			public void onSuccess(int statusCode, Header[] headers, byte[] responseBody)
			{
				String content=new String(responseBody);
				tvShowLog.setText("    :"+content);
			}
			@Override
			public void onFailure(int statusCode, Header[] headers,
					byte[] responseBody, Throwable error)
			{
				tvShowLog.setText("    ");
			}
		};
	}서버 엔 드 소스 세 션:
	@RequestMapping(params="cmd=uploadFiles")
	@ResponseBody
	public JsonResult uploadFiles(@RequestParam Integer albumId,HttpServletRequest  request, HttpServletResponse response){
		JsonResult jsonResult = new JsonResult(true);
		try {
			//  request MultipartHttpServletRequest  
			MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;  
			//       
			Map fileMap = multipartRequest.getFileMap();
			//         
			for (Map.Entry entity : fileMap.entrySet()) {
				//         
				MultipartFile mf = entity.getValue();  
				//      ,       ,                    
				byte[] bytes = mf.getBytes();
				//          
				String fileName = mf.getOriginalFilename();  
			}
		} catch (Exception e) 
		{
		}
		return jsonResult;
	}  Spring 의 Util 패키지 에서 FileCopyUtils 도구 류 를 사용 하여 이 바이트 배열 을 원가 의 그림 파일 로 저장 할 수 있 습 니 다.
FileCopyUtils.copy(mf.getBytes(), “D:\ImageUpload\xxx.jpg);OK, 여기까지.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Bitrise에서 배포 어플리케이션 설정 테스트하기이 글은 Bitrise 광고 달력의 23일째 글입니다. 자체 또는 당사 등에서 Bitrise 구축 서비스를 사용합니다. 그나저나 며칠 전 Bitrise User Group Meetup #3에서 아래 슬라이드를 발표했...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.