Reputation: 95
I'm working on an app which will use the amazon aws s3 imdb bucket called "imdb-datasets" to display various movie info. Before trying this i tested the code with my own bucket and managed to upload and download a testfile from my android device to my bucket and vice versa. But upon trying the same method with the imdb-datasets bucket i started getting an acess denied error 403. After doing some research i found out that the possible issue would be that i have to specify in the code that it is a requester-pays bucket. I tried to implement the requester pays bit (the commented out code) but it crashes my application. I have no idea how to implement it in my app as i didn't manage to find any guide or solution. Any ideas how to do that?
Edit: I have also given permissions for the app to be able to access storage, both through manifest and manually in the app through the android device settings. Role policies with the iam user and the imdb bucket are also assigned.
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.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.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import java.io.File;
public class movieChooseActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movie_choose);
}
public void getFile(View v) {
File sdcard = Environment.getExternalStorageDirectory();
String key = "documents/v1/current/title.basics.tsv.gz";
File file = new File(key, "title.basics.tsv.gz");
// Initialize the Amazon Cognito credentials provider
CognitoCachingCredentialsProvider credentialsProvider = new
CognitoCachingCredentialsProvider(
getApplicationContext(),
"eu-west-2:4c829519-0596-4fdb-ad04-6b8912e44164", // Identity
//pool ID
Regions.EU_WEST_2 // Region
);
AmazonS3 s3 = new AmazonS3Client(credentialsProvider);
s3.setRegion(Region.getRegion(Regions.US_EAST_1));
//include the appropriate request-payer parameter
//s3.getObject(new GetObjectRequest("imdb-datasets",
key).withRequesterPays(true));
TransferUtility transferUtility = new TransferUtility(s3,
getApplicationContext());
TransferObserver transferObserver = transferUtility.download("imdb-
datasets","title.basics.tsv.gz",file);
transferObserver.setTransferListener(new TransferListener() {
@Override
public void onStateChanged(int i, TransferState state) {
Log.e("statechange",state + " ");
if(state == state.COMPLETED) {
Toast.makeText(movieChooseActivity.this, "File transfered",
Toast.LENGTH_LONG).show();
}
if(state == state.FAILED) {
Toast.makeText(movieChooseActivity.this, "Failed",
Toast.LENGTH_LONG).show();
}
}
@Override
public void onProgressChanged(int i, long l, long l1) {
}
@Override
public void onError(int i, Exception e) {
Log.e("whattowatchapp","Error:"+ e.getMessage());
}
});
}
}
Upvotes: 1
Views: 452
Reputation: 4491
Files are located under documents/v1/*
In your example the Key is just title.basics.tsv.gz
In their code example here
private static String bucketName = "imdb-datasets";
private static String key = "documents/v1/current/name.basics.tsv.gz";
public static void main(String[] args) throws IOException, InterruptedException {
ProfileCredentialsProvider credentialsProvider =
new ProfileCredentialsProvider("*** FULL PATH TO AWS CREDENTIALS FILE ***",
"*** CREDENTIALS PROFILE NAME ***");
AmazonS3 s3Client = new AmazonS3Client(credentialsProvider);
try {
// Note: It's necessary to set RequesterPays to true
GetObjectRequest getObjectRequest = new GetObjectRequest(bucketName, key)
.withRequesterPays(true);
http://www.imdb.com/interfaces/
I don't know what the app is for or does but a reminder about their License
You can hold local copies of this data, and it is subject to our terms and conditions. Please refer to the Non-Commercial Licensing and copyright/license and verify compliance.
Upvotes: 0