私のコードギャラリーからパースサーバーに画像をアップロードするにはどうすればいいですか?ここで
パブリッククラスTestingActivityがAppCompatActivityここ{
Button btn_testing;
ProgressDialog pDialog;
ImageView iv_image;
Bitmap bMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.testing);
btn_testing = (Button)findViewById(R.id.btn_testing);
iv_image = (ImageView)findViewById(R.id.iv_imagetesting);
FileInputStream in;
BufferedInputStream buf;
try
{
in = new FileInputStream("/storage/emulated/0/Pictures/InstaTag_Edit_20160427_131230-346274175.jpg");
buf = new BufferedInputStream(in,1070);
System.out.println("1.................."+buf);
byte[] bMapArray= new byte[buf.available()];
buf.read(bMapArray);
bMap = BitmapFactory.decodeByteArray(bMapArray, 0, bMapArray.length);
iv_image.setImageBitmap(bMap);
if (in != null)
{
in.close();
}
if (buf != null)
{
buf.close();
}
}
catch (Exception e) {
Log.e("Error reading file", e.toString());
}
btn_testing.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pDialog = new ProgressDialog(TestingActivity.this);
pDialog.setMessage("Loading...");
pDialog.show();
Bitmap bitmap = ((BitmapDrawable)iv_image.getDrawable()).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Compress image to lower quality scale 1 - 100
bMap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
ParseFile file = new ParseFile("androidbegin.png", image,"image/png");
file.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
try {
pDialog.dismiss();
} catch (Exception e1) {
}
if (e == null) {
Toast.makeText(TestingActivity.this, "Image saved", Toast.LENGTH_LONG).show();
} else {
e.printStackTrace();
Toast.makeText(TestingActivity.this, "Image not saved", Toast.LENGTH_LONG).show();
}
}
});
}
});
}
}
私のログレスポンスで拡張している:
8月29日19:23:28.569 7072を-7072/com.appcentricsoftware.bumbysdigital W/System.err:com.parse.ParseRequest $ ParseRequestException:悪いjson応答 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:com.parse.ParseRequest.newTemporaryException(ParseRequest.java:290) 08-29 19:23:28.570 7072-7072 /com.appcentricsoftware.bumbysdigital W/System.err:com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:308) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err :com.parse.ParseRequest $ 3.then(ParseRequest.java:137) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:com.parse.ParseRequest $ 3.then (ParseRequest.java:133) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:bolts.Task $ 15.run(Task.java:917) 08-29 19 :23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:at bolts.BoltsExecutors $ ImmediateExecutor.execute(BoltsExecuto rs.java:105) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:bolts.Task.completeAfterTask(Task.java:908) 08-29 19:23 :28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:at bolts.Task.continueWithTask(Task.java:715) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:at bolts.Task.continueWithTask(Task.java:726) 08-29 19:23:28.570 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:at bolts.Task $ 13.then(タスク.java:818) 08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:bolts.Task $ 13.then(Task.java:806) 08-29 19:23 :28.571 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:ボルトで$ 15.run(Task.java:917) 08-29 19:23:28.571 7072-7072 /com.appcentricsoftware.bumbysdigital W/System.err:at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital W/System .err:at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:588) 08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:at java.lang .Thread.run(Thread.java:818) 08-29 19:23:28.571 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:原因:org.json.JSONException:java.lang型の値.StringはJSONObjectに変換できません 08-29 19:23:28.578 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:at org.json.JSON.typeMismatch(JSON.java:111) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:org.json.JSONObject。(JSONObj (JSONObject.java:173) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:org.json.JSONObject。(JSONObject.java:173) 08-29 19: 23:28.579 7072-7072/com.appcentricsoftware.bumbysdigital W/System.err:com.parse.ParseRESTCommand.onResponseAsync(ParseRESTCommand.java:298) 08-29 19:23:28.579 7072-7072/com.appcentricsoftware。 bumbysdigital W/System.err:...13以上
'文字列JSONObject'に変換することはできません...ここではコード内にJSONObjectが表示されません –
私はちょうどsaveInBackgroundを使用しています()を呼び出してParseFileを保存し、この問題を解決します。 – Puri