Saturday, February 12, 2011

Re: [android-developers] Re: Corrupted images when uploading to server via POST

yes a iknow, but if he maybe get an ANR, the images could be corrupted
if not fully uploads them.
of corse he didn't write anything about he would have an ANR.


On 12 February 2011 09:35, Indicator Veritatis <mej1960@yahoo.com> wrote:
> You are right, it is a bad idea to do it in the UI thread, but his
> problem is not the problem one would expect from doing it in a UI
> thread. That is, given that his failure takes place in his existing
> code, I would expect the same failure to take place once he has moved
> it to a worker thread.
>
> After all, the error we expect due to doing network in the UI thread
> is the infamous ANR. But that is not what he is getting. He is getting
> missing stuff in the uploaded files.
>
> On Feb 11, 3:41 pm, Gergely Juhász <jg.sv...@gmail.com> wrote:
>> It is a realy bad idea to make network communication in the ui thread.
>> You should always make net io in a worker thread.
>>
>> On 8 February 2011 15:45, alex c <alex.chuny...@gmail.com> wrote:
>>
>> > ello.
>> > i'm experiencing a problem when uploading images from my android
>> > application to remote server (apache with php).
>>
>> > devices are: htc hd2 and samsung galaxy tab. all with android 2.2
>>
>> > the application itself is very simple:
>> > public class UploadTest extends Activity {
>> >        private final static String TAG = "UploadTest";
>>
>> >        /** Called when the activity is first created. */
>> >        @Override
>> >        public void onCreate(Bundle savedInstanceState) {
>> >                super.onCreate(savedInstanceState);
>> >                setContentView(R.layout.main);
>> >        }
>>
>> >        private void uploadImage() {
>> >                String imagePath = Environment.getExternalStorageDirectory()
>> >                                + "/Andorra/Images/748.jpg";
>> >                String exportUrl = "http://domainname.here/pda/export_photos.php";
>>
>> >                String responseStr = "";
>>
>> >                MultipartEntity reqEntity = new
>> > MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
>>
>> >                reqEntity.addPart("image", new FileBody(new File(imagePath), "image/
>> > jpeg"));
>> >                HttpResponse resp = NetworkUtils.sendHttpRequestMultipart(exportUrl,
>> > reqEntity);
>>
>> >                new AlertDialog.Builder(this).setMessage(responseStr)
>> >                                .setTitle("Finished")
>> >                                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
>> >                                        public void onClick(DialogInterface dialog, int whichButton) {
>> >                                        }
>> >                                }).show();
>>
>> >        }
>>
>> >        public void btn1_onClickHandler(View v) {
>> >                uploadImage();
>> >        }
>> > }
>>
>> > so it's as simple as it can be.
>> > the problem is that the uploaded image is corrupted.
>> > the file size is same. but content can differ. sometimes it uploads
>> > ok. sometimes it is broken..
>> > example:
>> > original image;http://pixelbirthcloud.com/corrupted_images/1_orig.jpg
>> > uplaoded image:http://pixelbirthcloud.com/corrupted_images/1_corrupted.jpg
>>
>> > the binary diff says:
>> > ------------------------------------------------------------------------
>>
>> > 00051330 | 49 69 11 4B 9D E6 | 00051330 | DA BB 10 70 DC 77 |
>> > 00051338 | 2D B9 1B B9 E4 81 5A E6 | 00051338 | AC 20 C7 90 7E B4 33
>> > 80 |
>> > 00051340 | D4 14 B0 F4 EA 3D D1 E9 | 00051340 | 31 9A B8 C2 29 83 66
>> > 9C |
>> > 00051348 | 61 9D E3 38 F7 36 DE 63 | 00051348 | 9A 84 8E 73 9A 8D B5
>> > 29 |
>> > 00051350 | 25 9D 9D C4 64 C3 23 AA | 00051350 | 18 60 1C 0F 7A CF 33
>> > 01 |
>> > 00051358 | 4A EB 08 C3 97 7C 8C 36 | 00051358 | D4 F0 7A D3 24 BA 85
>> > 71 |
>> > 00051360 | 73 F5 E3 15 14 5B BC C1 | 00051360 | F3 0A 76 8A D6 C4 36
>> > 5E |
>> > 00051368 | B9 A4 49 06 71 1B 11 87 | 00051368 | 7B B9 5F 20 E3 A5 46
>> > F2 |
>> > 00051370 | 39 E7 76 7B 8F 5F | 00051370 | B8 1D 4E 6B 36 6D |
>> > ------------------------------------------------------------------------
>>
>> > internet connection is 3g in my case and slow wifi in client's case.
>> > for client the images are 90% corrupted (cannot see anything) and it
>> > happens like 98% of the time.
>>
>> > after some time i tried to make the upload using HttpURLConnection
>> > class and had same results.
>> > then tried to encode files with base64 but even in this case the
>> > base64 text is received corrupted.
>>
>> > also tries to set transfer to chunk mode:
>> > HttpURLConnection conn = (HttpURLConnection) url.openConnection();
>> > conn.setChunkedStreamingMode(8192);
>> > but the result was same.. most images are corrupt.
>>
>> > can you please help me? i am almost crying =) fighting with this for a
>> > week now.. thank you in  advance
>>
>> > btw. tried it with emulator via normal network and it works ok...
>>
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups "Android Developers" group.
>> > To post to this group, send email to android-developers@googlegroups.com
>> > To unsubscribe from this group, send email to
>> > android-developers+unsubscribe@googlegroups.com
>> > For more options, visit this group at
>> >http://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment