上传文件不适用于Android

时间:2015-09-03 19:45:19

标签: android amazon-s3 media transfer

您好我尝试将虚拟文本文件上传到Amazon S3。但它不起作用,但日志生成了一个id。当我刷新Amazon S3存储桶仪表板时。该文件尚未转移。

public class AmazonService extends AsyncTask<String, Boolean, Boolean> {
    Context mContext;
    public AmazonService(Context context) {
        mContext = context;
    }

    @Override
    protected Boolean doInBackground(String... params) {
        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                mContext,
                "us-east-1:ec361bf5-52b9-477b-9a68-7e2b5f70de07", // Identity Pool ID
                Regions.US_EAST_1 // Region
        );
        AmazonS3Client client =
                new AmazonS3Client(credentialsProvider);
        TransferUtility transferUtility = new TransferUtility(client, mContext);
        TransferObserver observer = transferUtility.upload("elevator-app","Video/",new File("dummy.txt") );
        Log.d("Test", observer.getId() + " " + observer.getBytesTransferred());

        return true;
    }
}

// AndroidManifest.xml中需要的服务

<service android:name= "com.amazonaws.mobileconnectors.s3.transferutility.TransferService" android:enabled="true" />

1 个答案:

答案 0 :(得分:9)

我遇到了同样的问题,原因是我将服务标签放在应用程序标签之外。当我将服务标签放在应用程序标签中时,一切都运行良好。