官网demo上传中testBucket, uploadObject, uploadFilePath这三个参数应该怎么填???求大神回答
// 上传
Button upload = (Button) findViewById(R.id.upload);
upload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
new PutObjectSamples(oss, testBucket, uploadObject, uploadFilePath).asyncPutObjectFromLocalFile();
}
}).start();
}
});
创建工具类 public class WinkUtils { public static ClientConfig getClientConfig(){ ClientConfig config=new ClientConfig(); SSLContext sc; try { sc=SSLContext.getInstance("SSL"); sc.init(null, getTrustManager(), new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); config.setBypassHostnameVerification(true); config.connectTimeout(100000); config.readTimeout(100000); config.followRedirects(false); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } return config; } public static TrustManager[] getTrustManager(){ TrustManager[] trustAllCerts=new TrustManager[]{ new X509TrustManager(){ public void checkClientTrusted(X509Certificate[] arg0,String arg1) throws CertificateException {} public void checkServerTrusted(X509Certificate[] arg0,String arg1) throws CertificateException {} public X509Certificate[] getAcceptedIssuers() { return null; } } }; return trustAllCerts; } } 第三步:写入图片数据到Bmob上 /** * 功能:根据传入的url路径插入图片数据 * @param url 上传图片的url路径 * @param data 传入到Bmob中的图片二进制数据 * @return 插入成功返回的json格式字符串 */ public static String setInsertGoodsData(String url,byte[] data){ String result=null; RestClient restClient=new RestClient(WinkUtils.getClientConfig()); Resource resource=restClient.resource(url); resource.header("X-Bmob-Application-Id", "你自己的APPID"); resource.header("X-Bmob-REST-API-Key",“你自己的APPKEY”); resource.header("Content-Type", "image/jpeg"); ClientResponse response=resource.post(data); int code=response.getStatusCode(); System.out.println("结果码:"+code); if(code==201){ result=response.getEntity(String.class); } return result; } 根据返回的result当中就包含图片上传之后在Bmob上的路径。操作完毕。
答案来源于网络
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。