java - 无法在 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.");
}
}
解决方案
您应该交叉检查上传路径与您用于从 S3 下载媒体文件的路径。我认为您正在使用不同的路径来下载媒体文件这就是您收到错误的原因。
推荐阅读
- javascript - 什么是在 Koa / Javascript 中实现 scala `Either[A,B]` 结构的方法
- firebase - Firebase 存储大小限制未强制执行
- ruby-on-rails - 如何在活动管理员上为同一页面定义多个分页器?
- angular - Angular 语言服务能否在 VS 2017 build 15.9.7 中工作?
- c# - C# 数据表问题
- c - 具有动态节点大小的 C 链表
- android - 跟踪移动本地数据库和可选云数据库之间的已删除条目
- c# - 使用 HtmlAgilityPack 为没有类的标签抓取数据
- hive - Hive SQL - 如何折叠具有连续日期范围的记录?
- python - 在 Python 3 中的每个条目后打印换行符