title: How to upload an image to S3 bucket using REST API in Android, Getting Forbidden Error: 403
body: <p>I want to upload media data to S3 bucket using REST API without using the Amazon SDK. I am getting “403 Forbidden Access Denied Error” on file upload to s3 bucket, please suggest suitable actions. If anything else is required I can share that too.</p>
  
  <pre><code>String bucket = getString(R.string.s3_bucket);
              RestAdapter.Builder builder = new RestAdapter.Builder()
                  .setEndpoint("http://" + bucket + ".s3.amazonaws.com")
                  .setLogLevel(RestAdapter.LogLevel.FULL)
                  .setClient(new OkClient(new OkHttpClient()));
  
              AwsS3 aws = builder.build().create(AwsS3.class);
  
              DateTimeFormatter fmt = DateTimeFormat.forPattern("EEE', 'dd' 'MMM' 'yyyy' 'HH:mm:ss' 'Z").withLocale(Locale.US);
              String ZONE = "GMT";
              DateTime dt = new DateTime();
              DateTime dateTime = dt.withZone(DateTimeZone.forID(ZONE)).plusHours(1);
              String formattedDate = dateTime.toString(fmt);
  
              try {
                  Bitmap bm = BitmapFactory.decodeFile(mCurrentPhotoPath);
                  ByteArrayOutputStream baos = new ByteArrayOutputStream();
                  bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
                  byte[] b = baos.toByteArray();
                  TypedInput body = new TypedByteArray("image/jpg", b);
                  String imageName = "files_" + System.currentTimeMillis();
                  String oauth = AWSOauth.getOAuthAWS(getApplicationContext(), imageName.trim());
                  String host = bucket + ".s3.amazonaws.com";
                  String mimeType = body.mimeType();
                  long length = body.length();
                  File file = new File(mCurrentPhotoPath);
                  RequestBody bb = RequestBody.create(MediaType.parse("image/jpeg"), file);
  
                  aws.upload(imageName.trim(),length,"/**",host,formattedDate,mimeType,oauth,bb,new Callback&lt;String&gt;(){
  
                      @Override
                      public void success(String s, Response response) {
                          Log.d("tag","S = " + s);
                          Log.d("tag","getHeaders = " + response.getHeaders());
                          Log.d("tag","Status = " + response.getStatus());
                      }
  
                      @Override
                      public void failure(RetrofitError error) {
                          Log.d("tag","error: S = " + error.getMessage());
                      }
                  });
              }catch (Exception e){
  
              }
  
  
   @PUT("/{Key}")
  void upload(@Path("Key") String Key,
                      @Header("Content-Length") long length,
                      @Header("Accept") String accept,
                      @Header("Host") String host,
                      @Header("Date") String date,
                      @Header("Content-type") String contentType,
                      @Header("Authorization") String authorization,
                      @Body RequestBody body,Callback&lt;String&gt; mCallback);
  </code></pre>