如何使用PHPAPI从图像视图传递图像进行解析

如何使用PHPAPI从图像视图传递图像进行解析,php,android,json,imageview,android-imageview,Php,Android,Json,Imageview,Android Imageview,我有一个api,它接受$\u文件['profile\u image']文件 我有一个android应用程序,它允许用户从外部媒体存储中选择一个图像,然后他们可以将其与许多其他editText字段等一起提交到API 如何将所选图像传递到API 以下是我的一些代码: 我目前拥有的android/java代码是: submit_button.setOnClickListener(new OnClickListener() { @Override public void

我有一个api,它接受$\u文件['profile\u image']文件

我有一个android应用程序,它允许用户从外部媒体存储中选择一个图像,然后他们可以将其与许多其他editText字段等一起提交到API

如何将所选图像传递到API

以下是我的一些代码:

我目前拥有的android/java代码是:

submit_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Boolean f;
            Boolean i;

            //Get All Fields
            Edi_First_Name          = (EditText)findViewById(R.id.Edi_First_Name);
            Edi_Last_Name           = (EditText)findViewById(R.id.Edi_Last_Name);
            image_preview           = (ImageView)findViewById(R.id.Reg_Profile_Image_Preview);

            //check if any fields are empty, if not proceed to api, else show errors
            f = Function.notEmpty("First Name", Edi_First_Name);
            f &= Function.notEmpty("Last Name", Edi_Last_Name);

            //check if image has been set
            i = Function.imageNotSet(image_preview);
            f &= i;

            if(f == true){
                //if everything is validated,talk to api.

                String first_name, last_name, company_name, job_title, email, contact, address_one, address_two, town, county, postcode, country, account_email, rep_account_email, account_password, rep_account_password;

                first_name          = Function.getEditText(Edi_First_Name);
                last_name           = Function.getEditText(Edi_Last_Name);

                //pass parameters so that we can call the register api via FUNCTIONS.java
                Function.registerCall(first_name, last_name, "test_image");
            }
            else{
                Toast.makeText(getApplicationContext(), "Error.", Toast.LENGTH_SHORT).show();
            }
        }
    });
那么看看代码,我如何将图像作为registerCall函数中的参数从imagview传递过来?然后,此函数向API发送http请求

有人能给我一个解决办法吗


谢谢

尽管我对PHP不熟悉,也许我可以为您指出正确的方向

首先,当用户从存储器中选择他的图像时,不仅要使用它来设置ImageView的内容,还要保留图像的路径(例如作为活动的一个字段)

然后,当调用api时,使用保存的文件路径

你应该如何处理你可能选择的路径(遵循本教程,
submit_button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            Boolean f;
            Boolean i;

            //Get All Fields
            Edi_First_Name          = (EditText)findViewById(R.id.Edi_First_Name);
            Edi_Last_Name           = (EditText)findViewById(R.id.Edi_Last_Name);
            image_preview           = (ImageView)findViewById(R.id.Reg_Profile_Image_Preview);

            //check if any fields are empty, if not proceed to api, else show errors
            f = Function.notEmpty("First Name", Edi_First_Name);
            f &= Function.notEmpty("Last Name", Edi_Last_Name);

            //check if image has been set
            i = Function.imageNotSet(image_preview);
            f &= i;

            if(f == true){
                //if everything is validated,talk to api.

                String first_name, last_name, company_name, job_title, email, contact, address_one, address_two, town, county, postcode, country, account_email, rep_account_email, account_password, rep_account_password;

                first_name          = Function.getEditText(Edi_First_Name);
                last_name           = Function.getEditText(Edi_Last_Name);

                //pass parameters so that we can call the register api via FUNCTIONS.java
                Function.registerCall(first_name, last_name, "test_image");
            }
            else{
                Toast.makeText(getApplicationContext(), "Error.", Toast.LENGTH_SHORT).show();
            }
        }
    });