1
我想在我的聊天应用程序中使用Cloudinary服务器上传图片,我已经阅读了关于上传图片的文档,我也注册了我自己在这个Cloudinary服务器上并获取api密钥,密钥,云名称和环境。 以下是我的图片加载代码。我如何在Android上使用cloudinary上传图片
public class ImageUpload extends Activity
{
private static boolean first = true;
private ProgressDialog dialog = null;
Cloudinary cloudinary;
JSONObject Result;
String file_path = "";
File file;
Button btnupload;
FileInputStream fileInputStream;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imageupload);
Intent i = getIntent();
btnupload = (Button)findViewById(R.id.btn_upload);
file_path = "/storage/emulated/0/Contacts_Cover/crop_ContactPhoto-IMG_20150814_152743.jpg";
HashMap config = new HashMap();
config.put("cloud_name", "chatgeeta");
config.put("api_key", "255663733636595");//I have changed the key and secret
config.put("api_secret", "5Upmclme1ydaTWBi7_COU7uIns0");
cloudinary = new Cloudinary(config);
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText(file_path);
file = new File(file_path);
try {
fileInputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public class Upload extends AsyncTask<String, Void, String>
{
private Cloudinary mCloudinary;
public Upload(Cloudinary cloudinary) {
super();
mCloudinary = cloudinary;
}
@Override
protected String doInBackground(String... params) {
String response ="";
try
{
Result = (JSONObject) mCloudinary.uploader().upload(fileInputStream, Cloudinary.emptyMap());
}
catch(Exception ex)
{
ex.printStackTrace();
}
return response;
}
@Override
protected void onPostExecute(String result) {
TextView textView = (TextView) findViewById(R.id.textView1);
textView.setText("file uploaded");
super.onPostExecute(result);
}}
public void upload(View view)
{
new Upload(cloudinary).execute();
}}
When i execute above code then i got "Caused by java.lang.NoClassDefFoundError:org.apache.commons.lang.StringUtils" as error.