首页 > 解决方案 > 无法在 Android 应用程序中下载从 Web 应用程序发送的媒体文件

问题描述

我正在开发聊天应用程序,我们有两个客户端,一个是 Android,另一个是 Web,我正在将媒体文件上传到S3-Amazon,当我将媒体文件从 Web 应用程序发送到 android 客户端时,媒体文件未下载显示错误如下. Media Download interrupted : com.amazonaws.services.s3.model.AmazonS3Exception: The specified key does not exist. (Service: Amazon S3; Status Code: 404; Error Code: NoSuchKey; Request ID: XXXXXXXXX), S3 Extended Request ID:XXXXXXXXXXX

private void beginDownload(String key, String bucket, String 
 mediaType,final 
DownloadFileFromAwsCompletionListener listener) {
    // Location to download files from S3 to. You can choose any 
accessible
    // file.

    String localFilePath = Strings.EMPTY;
    try {
        //if (!isThumb) {
        localFilePath = MediaHelper.createMediaFile(mediaType, false, false, key);
       /* } else {
            localFilePath = MediaHelper.createMediaFile(mediaType, false, true);
        }*/
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (!StringHelper.isNullOrEmpty(localFilePath)) {
        File file = new File(localFilePath);

        // Initiate the download
        TransferObserver observer = mTransferUtility.download(bucket, key, file);
        final String finalLocalFilePath = localFilePath;
        observer.setTransferListener(new TransferListener() {
            @Override
            public void onStateChanged(int id, TransferState state) {

                //String bucketPath = UrlStrings.XmppStrings.
                if (state.equals(TransferState.COMPLETED)) {
                    listener.onDownloadSuccess(finalLocalFilePath);
                }

            }

            @Override
            public void onProgressChanged(int id, long bytesCurrent, long bytesTotal) {

            }

            @Override
            public void onError(int id, Exception ex) {
                listener.onDatabaseError(new AwsFailure(ex));
            }
        });
    } else {
        getLogger().log(Strings.TAG, "xmpp beginDownload(): file could not be created.");
    }
}

标签: javaandroidamazon-s3

解决方案


您应该交叉检查上传路径与您用于从 S3 下载媒体文件的路径。我认为您正在使用不同的路径来下载媒体文件这就是您收到错误的原因。


推荐阅读