aclarkeesri-ireland-ie-esridist

Batch Upload of Attachments...

Discussion created by aclarkeesri-ireland-ie-esridist Employee on May 31, 2013
I wish to do some batch upload of attachments... (attachments are uploaded when the user has a good network coverage)

So as is typically done I created a background thread so as not to block the UI.

But I find that the Esri Android SDK Upload Attachments function uses callbacks - which makes uploading more than 1 attachment difficult -
Is there any easy way to block the background processing thread at the point ({1}) until ArcGISFeatureLayer::addAttachment() returns with a result- to make my function ESRI_SDKAttachmentAddLive work like calling the org.apache.commons.httpclient post functions directly would?

Thanks all.


        @Override protected Message /*AsyncTask::*/doInBackground(String... params)
        {
            ....
        private void ESRI_SDKAttachmentAddLive(String sURLBase, AttachInfo attachInfo, String sFeatureObjectID)
        {  //this is now in a non-ui thread.
            //issue - No blocks here -so will continue to run....not ideal for batch upload of images
            try
            {
                final ArcGISFeatureLayer fl = new ArcGISFeatureLayer(sURLBase, MODE.SNAPSHOT);
                
                File file = new File(attachInfo.mFilename);
                //Note: fl.addAttachment will strip off the path for us
            fl.addAttachment(Integer.valueOf(sFeatureObjectID), file, "image/jpeg", new CallbackListener<FeatureEditResult>()
            {
                @Override public void onCallback(FeatureEditResult arg0)
                { //FeatureEditResult [objectId=2801, globalId=null, success=true, error=null]
                    Log.d(Utils.tag,"Image Uploaded OK");
                    {2}
                }
        
                @Override public void onError(Throwable arg0)
                {
                    Log.e(Utils.tag,"Error: "+arg0.getMessage());
                    {3}
                }
            } );
            }
            catch(Exception ex)
            {
                ex.printStackTrace();
                Log.e(Utils.tag,ex.getMessage());
            }
            
            //{1}want to block at this point - until we have a callback (good or bad) from the fl.addAttachment call 
        }

Outcomes