BasicScheme basicAuth = new BasicScheme();
localcontext.setAttribute( "preemptive-auth", basicAuth );
client.addRequestInterceptor( new PreemptiveAuth(), 0 );
}
URI url = URI.create( sUrl );
HttpPut p = new HttpPut( url );
try {
// new file and and entity
File file = new File( item.imagePath );
byte[] bytes = Utils.toByteArray( file );
ByteArrayEntity requestEntity = new ByteArrayEntity( bytes );
HttpParams params = client.getParams();
params.setParameter( CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1 );
params.setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer( 15000 ) );
params.setParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer( 15000 ) );
p.setEntity( requestEntity );
p.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
Log.i( TAG, "execute" );
HttpResponse response = client.execute( p );
StatusLine line = response.getStatusLine();
Log.i( TAG, "complete: " + line );
// return code indicates upload failed so throw exception
if( line.getStatusCode() < 200 || line.getStatusCode() >= 300 ) {
throw new Exception( "Failed upload" );
}
// shut down connection
client.getConnectionManager().shutdown();
// notify user that file has been uploaded
notification.finished();
} catch( Exception e ) {
Log.e( TAG, "exception: " + sUrl, e );
// file upload failed so abort post and close connection
p.abort();
client.getConnectionManager().shutdown();
// get user preferences and number of retries for failed upload
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( context );
int maxRetries = Integer.valueOf( prefs.getString( "retries", "" ).substring( 1 ) );