gpt4 book ai didi

java - 访问被拒绝错误 imdb s3 存储桶

转载 作者:太空宇宙 更新时间:2023-11-04 11:02:14 25 4
gpt4 key购买 nike

我正在开发一个应用程序,它将使用名为“imdb-datasets”的亚马逊 aws s3 imdb 存储桶来显示各种电影信息。在尝试此操作之前,我使用自己的存储桶测试了代码,并设法将测试文件从我的 Android 设备上传和下载到我的存储桶,反之亦然。但是,在对 imdb-datasets 存储桶尝试相同的方法后,我开始收到访问被拒绝错误 403。经过一些研究,我发现可能的问题是我必须在代码中指定它是请求者付费存储桶。我尝试实现请求者付费位(注释掉的代码),但它使我的应用程序崩溃。我不知道如何在我的应用程序中实现它,因为我没有找到任何指南或解决方案。有什么想法如何做到这一点吗?

编辑:我还授予应用程序能够访问存储的权限,既可以通过 list ,也可以通过 Android 设备设置在应用程序中手动访问。还分配了 iam 用户和 imdb 存储桶的角色策略。

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());
}
});
}

}

最佳答案

Files are located under documents/v1/*

在您的示例中, key 只是 title.basics.tsv.gz

在他们的代码示例中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/

我不知道该应用程序的用途或用途,但提醒其许可证

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.

关于java - 访问被拒绝错误 imdb s3 存储桶,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46774813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com