title: How to set permission when uploading file to amazon s3 in android
body: <p>In android when i upload a file to aws s3. It was uploaded successfully. But the uploaded file have no public permission. It cannot access by public.</p>
  
  <p>TransferObserver transferObserver = transferUtility.upload("appname","filename",file);</p>
  
  <p>But when i rewrite the code as </p>
  
  <p>TransferObserver transferObserver = transferUtility.upload("acs-android","filename",file,CannedAccessControlList.PublicRead);</p>
  
  <p>for accessing public permission it shows an error. </p>
  
  <p>Error : Unable to execute HTTP request: Write error: ssl=0xb8f43420: I/O error during system call, Connection reset by peer.</p>
  
  <p>The full code is </p>
  
  <pre><code>import android.os.Environment;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;   
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Toast;
  import com.amazonaws.auth.CognitoCachingCredentialsProvider;
  import com.amazonaws.mobileconnectors.s3.transferutility.TransferListener;
  import com.amazonaws.mobileconnectors.s3.transferutility.TransferObserver;
  import com.amazonaws.mobileconnectors.s3.transferutility.TransferState;
  import com.amazonaws.mobileconnectors.s3.transferutility.TransferUtility;
  import com.amazonaws.regions.Regions;
  import com.amazonaws.services.s3.AmazonS3;
  import com.amazonaws.services.s3.AmazonS3Client;
  import com.amazonaws.services.s3.model.AccessControlList;
  import com.amazonaws.services.s3.model.CannedAccessControlList;
  import com.amazonaws.services.s3.model.GroupGrantee;
  import com.amazonaws.services.s3.model.Permission;
  import com.amazonaws.services.s3.model.Region;
  
  import java.io.File;
  
  public class MainActivity extends AppCompatActivity {
  
  Button button;
  
  File sdcard = Environment.getExternalStorageDirectory();
  File file = new File(sdcard,"filename");
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      button = (Button) findViewById(R.id.button);
  
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              fileUpload();
          }
      });
  }
  
  private void fileUpload() {
  
  // Initialize the Amazon Cognito credentials provider
      CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
              getApplicationContext(),
              "xxx:7e4xxx-xxxxxxxxx-xx-48cfc8f79f6", // Identity Pool ID
              Regions.REGION // Region
      );
  
      AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
      s3.setRegion(com.amazonaws.regions.Region.getRegion(Regions.REGION));
  
      TransferUtility transferUtility = new TransferUtility(s3, this);
  
  
  
      TransferObserver transferObserver = transferUtility.upload("appname","filename",file,CannedAccessControlList.PublicRead);
  
  
      transferObserver.setTransferListener(new TransferListener() {
          @Override
          public void onStateChanged(int id, TransferState state) {
              if(state == TransferState.COMPLETED) {
                  Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_SHORT).show();
              }
  
          }
  
          @Override
          public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {
  
          }
  
          @Override
          public void onError(int id, Exception ex) {
  
              Log.e("LOGTAG", "Error : " + ex.getMessage());
  
          }
      });
  
  }
  }
  </code></pre>