I have an api that aceepts the $_FILES['profile_image'] File.
I have an android application that enables the user to select a image from their external media storage and they can then submit it along with many other editText fields etc to the API.
How can I pass the selected image to the API?
Here is some of my code:
$return = array();
switch($_REQUEST['action']){
case 'register':
$v = true;
$fields = array('u_first_name', 'u_last_name');
foreach($fields as $f)
${$f} = $_REQUEST[$f];
$image_file = $_FILES['profile_image'];
//validate, upload image and manipulate db
}
The current android/java code I have is:
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();
}
}
});
So looking at the code, how can I pass the image from the imagview as a parameter in the registerCall Function? This function then sends a http request to the API.
Can anyone offer me a solution?
Thanks