【问题标题】:Amazon s3 upload using transfer manager seems to never stop waiting使用传输管理器上传 Amazon s3 似乎永远不会停止等待
【发布时间】:2019-07-07 18:37:01
【问题描述】:

我正在尝试创建一项服务以在后台上传文件列表。当我定期检查MultipleFileUpload对象时,它始终处于TransferState WAITING,上传的字节数和要上传的总字节数始终为0。在服务中运行TransferManager,或者定期检查MultipleFileUpload这种方式是否有问题?

我已经在手机和模拟器上进行了测试。当我使用 PutObjectRequest 而不是 TransferManager 时,我之前能够使用相同的 AmazonS3Client 成功上传。

这是目前为止的代码:

// OnCreate
    @Override
    public void onCreate() {

        Log.v(TAG, "Creating Upload Service");

        ClientConfiguration clientConfig=new ClientConfiguration();
        clientConfig.setConnectionTimeout(10*1000);

        AmazonS3Client s3Client = new AmazonS3Client(
                new BasicAWSCredentials(ACCESS_KEY_ID,
                        SECRET_KEY),clientConfig);

        s3Client.setEndpoint(AMAZON_ENDPOINT);

        transferManager= new TransferManager(s3Client);

        seekIntent = new Intent(BROADCAST_ACTION);
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        // Insert notification start
        initNotification();

        String[] fileNames=intent.getExtras().getStringArray(MainActivity.UPLOAD_FILE_NAMES);

        String path=intent.getExtras().getString(MainActivity.UPLOAD_FILE_PATH);

        ArrayList<File> files=new ArrayList<File>();

        for (String fileName : fileNames) {
            files.add(new File(fileName));
        }

        upload= transferManager.uploadFileList(RECORDING_BUCKET, null,new File(path),files);
        seekIntent.putExtra(UPLOAD_BYTES_TOTAL_KEY, upload.getProgress().getTotalBytesToTransfer());

        transferManager.

        setupHandler();

        return START_STICKY;
    }

    // ---Send seekbar info to activity----
    private void setupHandler() {
        handler.removeCallbacks(sendUpdatesToUI);
        handler.postDelayed(sendUpdatesToUI, 1000); // 1 second
    }

    private Runnable sendUpdatesToUI = new Runnable() {
        public void run() {
            // // Log.d(TAG, "entered sendUpdatesToUI");

            seekIntent.putExtra(UPLOAD_BYTES_TRANSFERED_KEY, upload.getProgress().getBytesTransfered());

            if(upload.isDone())
            {
                int retCode=(upload.getState()==TransferState.Completed)?0:1;

                seekIntent.putExtra(UPLOAD_COMPLETION_CODE_KEY, retCode);
            }
            else
            {
                handler.postDelayed(this, 1000); 
            }

            sendBroadcast(seekIntent);
        }
    };

【问题讨论】:

    标签: android amazon-web-services amazon-s3


    【解决方案1】:

    原来我对uploadFileList方法的参数理解有误。我传入的文件是相对于目录文件的。事实证明,文件列表中的文件仍然需要它们的完整路径,而目录参数只是确定它们应该如何在存储桶中显示。奇怪的是这并没有导致错误,它只是导致我在问题中提到的行为。

    【讨论】:

      【解决方案2】:

      我发现的另一个问题是,如果使用新的 TransferUtility,则必须声明 Service

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

      在您的 AndroidManifest.xml 中。这在一些但不是所有的文档中都突出显示,很容易错过。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-08
        • 2017-09-08
        • 2016-06-05
        • 2023-04-09
        • 1970-01-01
        • 1970-01-01
        • 2015-05-29
        • 1970-01-01
        相关资源
        最近更新 更多