Carregar foto para o servidor
Eu pesquisei muito, mas não funciona. Eu encontrei muitos sites com informações, mas por todos os sites que meu aplicativo caiu. A imagem que eu quero abrir é: "lastfile.png". Ele é armazenado no armazenamento interno, então eu abro com openFileInput ("lastfile.png");
Eu faço isso em um AsyncTask.
Este é o meu código até agora:
class PostTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
if(picture == null) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
responseString = out.toString();
} else{
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
Toast.makeText(AddStoryActivity.this, getResources().getString(R.string.error), Toast.LENGTH_LONG).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(AddStoryActivity.this, getResources().getString(R.string.error), Toast.LENGTH_LONG).show();
e.printStackTrace();
}
return responseString;
} else {
/* IMAGE UPLOAD */
}
return "";
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
progress.cancel();
Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();
}
}