java - AmazonS3Client.putObject doesn't work if I call AmazonS3Client.listObjects first -


i've been trying long time solve this, without success. i'm using aws android sdk upload files aws s3, , files upload server, others doesn't. putobject instruction executed, "hangs up" , lock code execution on line.

by trying comment pieces of code find source of problem, concluded happens because call listobjects before uploads.

i can't remove listobjects because need fetch file names when app starts, , uploads take place after user selected wants upload.

i upload photos cell, 1 1.3 mb, , concludes upload in less 30 seconds. if call listobjects "hangs up". why happenning? have clue of going on? here goes few lines of code:

during android oncreate:

weather_data = new arraylist<weather>();         objectlisting objectlisting = s3client.listobjects(new listobjectsrequest().withbucketname(lista_de_baldes.get(0).getname()).withprefix("thumbs")); (s3objectsummary objectsummary : objectlisting.getobjectsummaries())     weather_data.add(new weather(r.drawable.jogo, objectsummary.getkey().replace("thumbs/", ""))); 

after user selected photo upload (executed during doinbackground class extends asynctask prevent main thread freezing):

file arquivo = new java.io.file(filepath); putobjectrequest por = new putobjectrequest(     lista_de_baldes.get(0).getname(),     filepath.substring(filepath.lastindexof('/') + 1),     arquivo ); s3client.putobject(por); 

they ulso using same bucket, same region , same zone. objectlisting runs fine.


edit: "solved" problem setting amazons3client variable again in upload code. this:

s3client = new amazons3client(            new basicawscredentials(constants.access_key_id, constants.secret_key)        ); s3client.setregion(region.getregion(regions.sa_east_1)); 

but doesn't make sense me, because global variable. looks simples got "locked" after downloaded list of objects. have idea going on?


edit: requested, here goes more of code.

@override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      s3client = new amazons3client(                    new basicawscredentials(constants.access_key_id, constants.secret_key)                    );     //mudei de us_west_2 para sa_east_1 (south america) para acessar um bucket criado em sp/brazil     s3client.setregion(region.getregion(regions.sa_east_1));      lista_de_baldes = s3client.listbuckets();      setcontentview(r.layout.main);      weather_data = new arraylist<weather>();             objectlisting objectlisting = s3client.listobjects(new listobjectsrequest().withbucketname(lista_de_baldes.get(0).getname()).withprefix("thumbs"));     (s3objectsummary objectsummary : objectlisting.getobjectsummaries()) {         file arquivo_thumb = new file(getcachedir() + file.separator + objectsummary.getkey().replace("thumbs/", ""));         weather_data.add(new weather(r.drawable.jogo, arquivo_thumb.getname().replace(".png", ".jpg")));          if(arquivo_thumb.exists())             continue;          inputstream input = null;         try {             responseheaderoverrides override = new responseheaderoverrides();             override.setcontenttype("image/jpeg");             generatepresignedurlrequest urlrequest = new generatepresignedurlrequest(                     lista_de_baldes.get(0).getname(),                     "thumbs/" + arquivo_thumb.getname()                     );             urlrequest.setresponseheaders(override);             url url = s3client.generatepresignedurl(urlrequest);                             ...          } 

the upload part:

     protected s3taskresult doinbackground(uri... uris) {          if (uris == null || uris.length != 1) {             return null;         }          // file location of image selected.         uri selectedimage = uris[0];          string[] filepathcolumn = { mediastore.images.media.data };          cursor cursor = getcontentresolver().query(selectedimage,                 filepathcolumn, null, null, null);         cursor.movetofirst();          int columnindex = cursor.getcolumnindex(filepathcolumn[0]);         filepath = cursor.getstring(columnindex);         cursor.close();          s3taskresult result = new s3taskresult();          // put image data s3.         try {                                // content type determined file extension.             file arquivo = new java.io.file(filepath);             putobjectrequest por = new putobjectrequest(                     lista_de_baldes.get(0).getname(),                     filepath.substring(filepath.lastindexof('/') + 1),                     arquivo                     );             por.setcannedacl(cannedaccesscontrollist.publicread);             s3client.putobject(por); 

is listobjects wrapped in asynctask? wait until listobjects finishes? fyi, since honeycomb level 11, multiple asynctask instances executed sequentially default.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -