Note that there are some explanatory texts on larger screens.

plurals
  1. POProblems with picture uploading
    primarykey
    data
    text
    <p>I have this activity in which the user can either choose one image from Gallery or just take a picture and (along with other data) upload it to a website.</p> <p>So far I've encountered 2 different problems:</p> <p><strong>1)</strong> If I try it with a picture from the gallery, I get an IOException with message /external/images/media/2305: open failed: ENOENT (No such file or directory) That happens when it comes to open the file stream.</p> <p><strong>2)</strong> If I try it by taking the picture, it goes ok, but the encoded data string is composed of "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" (really longer, but only A's) and I guess that's not a good sign. This is only a guess since I still cannot properly upload it to the website, but different pictures showing the same data string just smells funny.</p> <p>The code here</p> <pre><code>@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case TAKE_PICTURE: if (resultCode == Activity.RESULT_OK) { //Uri selectedImage = imageUri; loadImage(imageUri); } break; case SELECT_PHOTO: if(resultCode == Activity.RESULT_OK){ imageUri = data.getData(); loadImage(imageUri); } } } </code></pre> <p>This is how I load the image (either pic taken or from the gallery) onto the ImageView. It works ok.</p> <pre><code>public void loadImage(Uri selectedImage){ mActivity.getContentResolver().notifyChange(selectedImage, null); ContentResolver cr = mActivity.getContentResolver(); Bitmap bitmap; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(cr, selectedImage); ivPicture.setImageBitmap(bitmap); ivPicture.setVisibility(View.VISIBLE); mActivity.croutonInfo(selectedImage.toString()); } catch (Exception e) { mActivity.croutonAlert("Failed to load"); e("Camera " + e.toString()); } } </code></pre> <p>This is the method I use to mock the data upload. When I get the API it will have an asynctask to deal with the http transfer, so far it only puts the data into a logicless transfer object</p> <pre><code>public void uploadTapa() throws IOException{ mActivity.croutonInfo("subiendo tapa "); d("uploadTapa new "); TapaUploadParametros tup = new TapaUploadParametros(); d("uploadTapa bar: " + nombreBar); tup.setBarNombre(etBarName.getText().toString()); d("uploadTapa tapa: " + nombreTapa); tup.setNombre(etTapaName.getText().toString()); d("uploadTapa municipio: " + municipio); tup.setLocalidad(municipio); d("uploadTapa provincia: " + provincia); tup.setProvincia(provincia); d("uploadTapa tipologiaId: " + tipologiaId); tup.setTipo(tipologiaId); d("uploadTapa precioId: " + precioId); tup.setPrecio(precioId); String encodedImage = encodeImgForHTTP(imageUri); d("uploadTapa encoded image: " + encodedImage); tup.setPic(encodedImage); d("uploadTapa direccionBar: " + direccionBar); tup.setBarDireccion(direccionBar); } </code></pre> <p>And this is the method to encode the image for http transfer. Images from gallery fail just after "before opening stream"</p> <pre><code> private String encodeImgForHTTP (Uri imageUri) throws IOException{ ContentResolver cr = mActivity.getContentResolver(); d("encodeImgForHTTP before opening stream "); FileInputStream fis = new FileInputStream(imageUri.getPath()); d("encodeImgForHTTP after opening stream "); // Get binary bytes for encode byte[] imageBytes = new byte[fis.available()]; d("encodeImgForHTTP after getting byte array "); // base 64 encode for text transmission (HTTP) d("encodeImgForHTTP pre 64: " + imageBytes); String data_string = Base64.encodeToString(imageBytes, Base64.URL_SAFE); d("encodeImgForHTTP before returning the encoded data string " + data_string); return data_string; } </code></pre> <p>What am I doing wrong with the gallery images? Why does the encoding of different pictures look the same?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload