안드로이드는 서버에 이미지를 업로드 할 수 없습니다

Therameshbista

나는 지난 며칠 동안 android.에 대한 초보자입니다. 내 이미지를 서버로 보내는 데 문제가 있습니다. 라이브러리에서 가져올 일부 텍스트 필드와 이미지를 포함하는 양식이 있습니다. 이미지 업로드를 제외하고 모든 것이 완벽하게 작동합니다 .Google에서 대부분의 자습서를 시도했습니다. 주된 문제는 logcat에 오류가 표시되지 않는다는 것입니다. 실제로 잘못되었습니다. 이것이 내가 한 일입니다

이 코드를 사용하여 갤러리에서 이미지를 얻었습니다.

 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);
    }

 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) {
            filePath = data.getData();
            try {
                bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
                schoolLogoUpload.setImageBitmap(bitmap);

            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

선택한 이미지를 서버로 보내기 위해이 기능을 작성했습니다.

public String getPath(Uri uri) {
        Cursor cursor = getContentResolver().query(uri, null, null, null, null);
        cursor.moveToFirst();
        String document_id = cursor.getString(0);
        document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
        cursor.close();

        cursor = getContentResolver().query(
                android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
        cursor.moveToFirst();
        String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
        cursor.close();

        return path;
    }


public void uploadMultipart() {
        //getting the actual path of the image
        String path = getPath(filePath);

        //Uploading code
        try {
            String uploadId = UUID.randomUUID().toString();

            //Creating a multi part request
            new MultipartUploadRequest(this, uploadId, UPLOAD_URL)
                    .addFileToUpload(path, "image") //Adding file
                    .setNotificationConfig(new UploadNotificationConfig())
                    .setMaxRetries(2)
                    .startUpload(); //Starting the upload

        } catch (Exception exc) {
            Toast.makeText(this, exc.getMessage(), Toast.LENGTH_SHORT).show();
        }
    }

이것은 서버 측에서 내 이미지 데이터를 수신하는 코드입니다.

if(Input::hasFile('image')) {
            $file = Input::file('image');
            $destination_path = "uploads";
            $extension = Input::file('image')->getClientOriginalExtension();
            $file_name = str_random(20). "." . $extension;
            Input::file('image')->move($destination_path, $file_name);
        }else{
            return \Response::json([
                "error"=>["message"=>"Please select the college logo"]
            ], 404);
스와 난드

이미지를 Base64형식으로 변환했다고 가정 합니다. 기본적으로 Base64형식은 이미지를 형식으로 변환 (또는 이미지 인코딩) String합니다.

* Asynctask당신을 위해 서버에 이미지를 업로드하는 작성 *

아래는 Asynctask:-

private class AsyncUploadToServer extends AsyncTask<String, Void, String>
{
    ProgressDialog pdUpload;

    String imageData = "";

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pdUpload = new ProgressDialog(MainActivity.this);
        pdUpload.setMessage("Uploading...");
        pdUpload.show();
    }

    @Override
    protected String doInBackground(String... params)
    {
        imageData = params[0];
        HttpClient httpclient = new DefaultHttpClient();

        // URL where data to be uploaded
        HttpPost httppost = new HttpPost(YOUR_URL_HERE);

        try
        {
            // adding data
            List<NameValuePair> dataToBeAdd = new ArrayList<>();
            dataToBeAdd.add(new BasicNameValuePair("uploadedImage", imageData));
            httppost.setEntity(new UrlEncodedFormEntity(dataToBeAdd));

            // execute http post request
            HttpResponse response = httpclient.execute(httppost);
            Log.i("MainActivity", "Response: " + response);
        }
        catch (ClientProtocolException ex)
        {
            ex.printStackTrace();
        }
        catch (IOException ioe)
        {
            ioe.printStackTrace();
        }
        return "";
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        pdUpload.dismiss();
        Toast.makeText(getApplicationContext(), "Image Uploaded Successfully..!!", Toast.LENGTH_SHORT).show();
    }
}

이것이 당신을 도울 것입니다. :-)

추신 :-asynctask에 대해 잘 모르는 경우 https://developer.android.com/reference/android/os/AsyncTask.html 링크가 있습니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Python에서 이미지를 업로드 할 수 없습니다.

분류에서Dev

Python에서 이미지를 업로드 할 수 없습니다.

분류에서Dev

개조 된 이미지를 서버에 업로드 할 수 없습니다.

분류에서Dev

이미지를 폴더에 업로드 할 수 없습니다.

분류에서Dev

이미지를 폴더에 업로드 할 수 없습니다.

분류에서Dev

TinyMCE는 IE11에서 이미지를 업로드 할 수 없습니다.

분류에서Dev

서버에 PHP로 이미지 파일을 업로드 할 수 없습니다.

분류에서Dev

서버 iOS에 이미지를 업로드 할 수 없음

분류에서Dev

500 서버 오류로 인해 서버에 이미지를 업로드 할 수 없습니다.

분류에서Dev

iOS의 서버에 이미지를 업로드 할 수 없습니까?

분류에서Dev

이미지를 업로드 할 수 없지만 자산에 pdf를 업로드 할 수 있습니다.

분류에서Dev

WordPress는 AWS Linux의 웹 서버에 이미지를 업로드 할 수 없습니다.

분류에서Dev

안드로이드 스튜디오 이미지보기에서 이미지를 표시 할 수 없습니다

분류에서Dev

Apache2 웹 서버에서 이미지를로드 할 수 없습니다.

분류에서Dev

Httprequest 라이브러리를 사용하여 서버에 이미지를 업로드 할 수 없습니다.

분류에서Dev

opencv (python)에서 이미지를로드 할 수 없습니다.

분류에서Dev

opencv (python)에서 이미지를로드 할 수 없습니다.

분류에서Dev

Gluon javafx에서 이미지를로드 할 수 없습니다.

분류에서Dev

HTML 업로드에서 Azure Blob에 이미지를 업로드 할 수 없습니다.

분류에서Dev

mongoDB 서버에 문서를 업로드 할 수 없습니다.

분류에서Dev

Firebase Cloud Storage에 이미지를 업로드 할 수 없습니다

분류에서Dev

Django 관리자에 이미지를 업로드 할 수 없습니다.

분류에서Dev

활성 저장소에 이미지를 업로드 할 수 없습니다.

분류에서Dev

Google Play 스토어에 이미지를 업로드 할 수 없습니다.

분류에서Dev

Facebook에 업로드 할 때 이미지를 가져올 수 없습니다.

분류에서Dev

주제에 이미지를 업로드 할 수 없습니다. nopCommerce mvc

분류에서Dev

부분보기 안에있는 이미지를로드 할 수 없습니까?

분류에서Dev

PHP 코드로 웹 페이지에 이미지를 업로드하고 표시 할 수 없습니다.

분류에서Dev

안드로이드 (10)에 미디어 스토어 MediaStore를 업데이트 할 수 없습니다

Related 관련 기사

  1. 1

    Python에서 이미지를 업로드 할 수 없습니다.

  2. 2

    Python에서 이미지를 업로드 할 수 없습니다.

  3. 3

    개조 된 이미지를 서버에 업로드 할 수 없습니다.

  4. 4

    이미지를 폴더에 업로드 할 수 없습니다.

  5. 5

    이미지를 폴더에 업로드 할 수 없습니다.

  6. 6

    TinyMCE는 IE11에서 이미지를 업로드 할 수 없습니다.

  7. 7

    서버에 PHP로 이미지 파일을 업로드 할 수 없습니다.

  8. 8

    서버 iOS에 이미지를 업로드 할 수 없음

  9. 9

    500 서버 오류로 인해 서버에 이미지를 업로드 할 수 없습니다.

  10. 10

    iOS의 서버에 이미지를 업로드 할 수 없습니까?

  11. 11

    이미지를 업로드 할 수 없지만 자산에 pdf를 업로드 할 수 있습니다.

  12. 12

    WordPress는 AWS Linux의 웹 서버에 이미지를 업로드 할 수 없습니다.

  13. 13

    안드로이드 스튜디오 이미지보기에서 이미지를 표시 할 수 없습니다

  14. 14

    Apache2 웹 서버에서 이미지를로드 할 수 없습니다.

  15. 15

    Httprequest 라이브러리를 사용하여 서버에 이미지를 업로드 할 수 없습니다.

  16. 16

    opencv (python)에서 이미지를로드 할 수 없습니다.

  17. 17

    opencv (python)에서 이미지를로드 할 수 없습니다.

  18. 18

    Gluon javafx에서 이미지를로드 할 수 없습니다.

  19. 19

    HTML 업로드에서 Azure Blob에 이미지를 업로드 할 수 없습니다.

  20. 20

    mongoDB 서버에 문서를 업로드 할 수 없습니다.

  21. 21

    Firebase Cloud Storage에 이미지를 업로드 할 수 없습니다

  22. 22

    Django 관리자에 이미지를 업로드 할 수 없습니다.

  23. 23

    활성 저장소에 이미지를 업로드 할 수 없습니다.

  24. 24

    Google Play 스토어에 이미지를 업로드 할 수 없습니다.

  25. 25

    Facebook에 업로드 할 때 이미지를 가져올 수 없습니다.

  26. 26

    주제에 이미지를 업로드 할 수 없습니다. nopCommerce mvc

  27. 27

    부분보기 안에있는 이미지를로드 할 수 없습니까?

  28. 28

    PHP 코드로 웹 페이지에 이미지를 업로드하고 표시 할 수 없습니다.

  29. 29

    안드로이드 (10)에 미디어 스토어 MediaStore를 업데이트 할 수 없습니다

뜨겁다태그

보관