private void getUploadToken() { final UploadManager uploadManager = new UploadManager(); mOSSKey = ""; StatueApi.getOssToken( new TextHttpResponseHandler() { @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { handler.sendEmptyMessage(HANDLER_IMAGE_UPLOAD_FAILED); } @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { try { mOSSToken = JsonUtils.getString("uptoken", new JSONObject(responseString.trim())); } catch (Exception e) { e.printStackTrace(); handler.sendEmptyMessage(HANDLER_IMAGE_UPLOAD_FAILED); } String tempKey = "monolog_" + MD5Utils.md5(String.valueOf(mThumbFile.hashCode())) + ".jpg"; uploadManager.put( mThumbFile, tempKey, mOSSToken, new UpCompletionHandler() { @Override public void complete(String key, ResponseInfo info, JSONObject response) { try { if (info.statusCode == 200) { // 上传图片返回key值 mOSSKey = JsonUtils.getString("key", response); handler.sendEmptyMessage(HANDLER_IMAGE_UPLOAD_SUCCESS); } else { handler.sendEmptyMessage(HANDLER_IMAGE_UPLOAD_FAILED); } } catch (Exception e) { e.printStackTrace(); handler.sendEmptyMessage(HANDLER_IMAGE_UPLOAD_FAILED); } } }, null); } }); }
private void post() { StatueApi.postCreateStatue( mEtText.getText().toString(), mOSSKey, String.valueOf(mLng), String.valueOf(mLat), new TextHttpResponseHandler() { @Override public void onFailure( int statusCode, Header[] headers, String responseString, Throwable throwable) { handler.sendEmptyMessage(HANDLER_PUBLISH_FAILED); } @Override public void onSuccess(int statusCode, Header[] headers, String responseString) { handler.sendEmptyMessage(HANDLER_PUBLISH_SUCCESS); } }); }