2
私はアプリケーションから私のサーバーにvolleyを使用して画像をアップロードしようとしていますが、画像のアップロードに失敗してVolley Error応答コードに移動しています。それは私にエラーメッセージなどを与えていません。Volleyを使用して画像をアップロード
ここは私のAndroidコードです。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri filePath = data.getData();
try {
//Getting the Bitmap from Gallery
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
//Setting the Bitmap to ImageView
btnCamera.setImageBitmap(bitmap);
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
private void showFileChooser() {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
public String getStringImage(Bitmap bmp){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
private void uploadImage(){
JSONObject js = new JSONObject();
String name = txtDesc.getText().toString();
try{
js.put("image", getStringImage(bitmap));
js.put("name", name);
Log.e("js", js.toString());
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.POST,UPLOAD_URL, js,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
Toast.makeText(ctx, "Success", Toast.LENGTH_LONG).show();
try{
String strSuccess = response.getString("code");
Log.d(TAG, strSuccess);
} catch (JSONException e)
{
Log.d(TAG, e.toString());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(ctx, "Failed", Toast.LENGTH_LONG).show();
}
});
VolleyRequestQueue.getInstance(ctx).addToRequestQueue(jsonObjReq);
} catch (JSONException e)
{
Log.e(TAG, e.toString());
}
}
PHPコード。
<?php
header('Content-type: application/json');
require_once 'db_config.php';
$json = file_get_contents('php://input');
$data = json_decode($json);
$image= $data->image;
$name = $data->name;
$actualpath = "http://46.101.2.231/FootballGroundGuide/stadium_images/$name" ;
file_put_contents($actualpath,base64_decode($image));
echo "Successfully Uploaded";
?>
'' file_put_contents'の[戻り値](http://php.net/manual/en/function.file-put-contents.php#refsect1-function.file-put-contents-returnvalues)を確認してみてください。 *この関数は、ファイルに書き込まれたバイト数を返すか、失敗した場合にはFALSEを返します。* – zwcloud
PHPの問題であると私に信じさせてくれるSUCCESSのことが始まります。 – xiimoss
file_put_contentsメソッドがアプリケーションに@ falseを返しています@zwcloud – xiimoss