last day (14 days later) » 

9:47 AM
1
Q: Upload Multiple Images but one by one

MoonActually in my application i have to upload multiple images one by one, but i have written code which allow me to upload multiple images at same time, but now i have to upload multiple images but one by one (only once at a time) like once user do tap on upload all button, it has to start with fir...

 
are you able to upload a single image ?
 
yes i am able to upload single image @Kedarnath thanks for coming
 
ok, and have you tried my answer ?
 
yes i tried your answer please see my edited answer with Log
 
Well, in your code, you are uploading only one image at time, which is based on position, correct ?
 
9:47 AM
yes exactly ... @Kedarnath
 
So, after editing code to for loop, isnt it uploading all the images one by one ?
are you getting any error ?
Hello @Moon
 
hi @Kedarnath
nice pic my moon at your head : good
 
hmm
So, after editing code to for loop, isnt it uploading all the images one by one ?
are you getting any error ?
 
yes i am facing error, let me place my log here for you
please wait
 
ok
 
10:01 AM
Line where getting error : position = Integer.parseInt(params[0]);
and complete log looks like this:

07-14 15:27:28.835: E/AndroidRuntime(10369): FATAL EXCEPTION: AsyncTask #1
07-14 15:27:28.835: E/AndroidRuntime(10369): java.lang.RuntimeException: An error occured while executing doInBackground()
07-14 15:27:28.835: E/AndroidRuntime(10369): at android.os.AsyncTask$3.done(AsyncTask.java:299)
07-14 15:27:28.835: E/AndroidRuntime(10369): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
07-14 15:27:28.835: E/AndroidRuntime(10369): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
@Kedarnath
 
Its java.lang.NumberFormatException
 
but bro when i am using this code to upload multiple images that time i am not getting this kind of error :
buttonUploadAll.setOnClickListener(new OnClickListener() {
// to upload whole list at once
for(int position = 0; position < lstView.getAdapter().getCount(); position++)
{
flags.put(position, true);
}
((BaseAdapter) lstView.getAdapter()).notifyDataSetChanged();
}
});
@Kedarnath
 
just a min
How come this for loop calling your startUpload() method ?
 
believe me don't know but it works for me
 
Can you upload full code of that file here ?
 
10:17 AM
sure
@Kedarnath check this bro : pastebin.com/Qui7JsDk
 
ok, just a min
 
sure take your time
 
10:33 AM
Please show me the code of SparseBooleanArray
 
no code
of SparseBooleanArray
this container keeps its mappings in an array data structure, using a binary search to find keys.
 
ok
 
hmmm..
 
What you get here Total number of Items are: ?
how many images you have in your SD card's location /mnt/sdcard/Pictures/AwesomePics/?
 
yes
total number of list items
 
10:41 AM
how many images ?
 
200
100
any number of images
20
 
is it giving you random result every time ?
 
yes
 
I am asking how many images you have in that folder ?
 
bro i am taking picture then browsing gallery
so any number of images
i hope you are getting my point
 
10:43 AM
ok
and then you want to upload all the gallery pics , right ?
 
yes images stored in gallery but it could be any folder with any name
try to understand my code
my flow
of working app
 
ok
 
read my code
once
i believe you will understand
 
but when you want to upload whole images from a folder then why you use these below lines ?
v = lstView.getChildAt(position - lstView.getFirstVisiblePosition()); ?
why you are reading images from list then ?
 
as i told you user can do single upload or multiple uploads
to get first visible position and to get upload specific image also
 
10:49 AM
okay
 
bro you have skills be patient and think will get result
i am also trying
 
When you click on uploadImageButton is it upload a single photo properly ?
 
yes
 
ok, do one thing,
paste this code and try again
buttonSync.setOnClickListener(new OnClickListener()
{
ImageList = getSD();

for ( int i = 0 ; i < ImageList.size() ; i++ )
{
flags.put(i, true);
UploadFileAsync uploader = new UploadFileAsync();

try {
uploader.execute((ImageList.get(i))).get();
Thread.sleep(1000); // a pause of 1 sec befor uploading next image.
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
((BaseAdapter) lstView.getAdapter()).notifyDataSetChanged();

});
 
bro are you kidding me, i already tried this way: stackoverflow.com/questions/24731838/…
 
11:03 AM
did you compare the code ?
 
yes this is what i tried:
buttonSync.setOnClickListener(new OnClickListener() {
ImageList = getSD();

for ( int i = 0 ; i < ImageList.size() ; i++ )
{
flags.put(i, true);
UploadFileAsync uploader = new UploadFileAsync();

try {
uploader.execute((ImageList.get(i))).get();
Thread.sleep(1000); // a pause of 1 sec befor uploading next image.
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}

}
((BaseAdapter) lstView.getAdapter()).notifyDataSetChanged();
}
 
ok.
Can you execute this code, and show me output please ?
buttonSync.setOnClickListener(new OnClickListener()
{
ImageList = getSD();

for ( int i = 0 ; i < ImageList.size() ; i++ )
{
Log.d ( "Image" , ImageList.get(i).toString() );
}
});
 

last day (14 days later) »