我已经查看了有关此问题的几个问题和答案,但是仍然无法上传到S3存储桶。我已经在应用程序标记中的清单中声明了该服务。每个日志语句都返回正确的信息,但是状态始终为WAITING,并且不会触发任何传输侦听器。我没有收到任何错误,并且S3存储桶仍然为空。我究竟做错了什么?public void uploadStoredItems() { TransferUtility transferUtility = TransferUtility.builder() .context(AWSProvider.getInstance().getContext()) .awsConfiguration(AWSProvider.getInstance().getConfiguration()) .s3Client(new AmazonS3Client(AWSProvider.getInstance().getIdentityManager().getCredentialsProvider())) .build(); try { for (File csvFile : csvFiles) { String filename = csvFile.getName(); //.substring(csvFile.getName().lastIndexOf('/') + 1); Log.d(TAG, "This is the filename for upload: " + filename); // FileReader reads text files in the default encoding. String line = null; FileReader fileReader = new FileReader(csvFile); // Always wrap FileReader in BufferedReader. BufferedReader bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { Log.d(TAG, "Here are the lines: " + line); } // Always close files. bufferedReader.close(); TransferObserver uploadObserver = transferUtility.upload(filename, csvFile); // Gets id of the transfer. Log.d(TAG, "This is the bucket: " + uploadObserver.getBucket()); Log.d(TAG, "This is the state: " + uploadObserver.getState()); Log.d(TAG, "This is the id: " + uploadObserver.getId());
1 回答
LEATH
TA贡献1936条经验 获得超6个赞
事实证明,我必须声明TransferUtility服务以与我调用它的服务正在运行的过程相同的方式运行:
<application
...
<service
android:name=".MainService"
android:enabled="true"
android:process=":main_service"
android:stopWithTask="false" />
<service
android:name="com.amazonaws.mobileconnectors.s3.transferutility.TransferService"
android:process=":main_service"
android:enabled="true" />
...
</application>
添加回答
举报
0/150
提交
取消