如何从 minio 服务器 URL 下载文件
这是URL 我从 minion 编码的响应中获取
这里我尝试解码从 minio 编码的 API 响应中获取的 URL
LoadingDialog.showLoadingDialog(getActivity(), "");
Call<DownloadInvoiceModelResponse> call = TransactionRetrofitClient.getInstance3().getAppApi().downloadInvoice("Bearer " + sharedPrefManager.getBearerToken(), transactionId);
call.enqueue(new Callback<DownloadInvoiceModelResponse>() {
@Override
public void onResponse(Call<DownloadInvoiceModelResponse> call, Response<DownloadInvoiceModelResponse> response) {
if (response.code() == 200) {
if (response.body().getObject()!=null && !response.body().getObject().equals("")){
url = response.body().getObject();
`Trying to decode the URL i am getting from response`
try {
result = URLDecoder.decode(url, "UTF-8");
Log.d("Decoded URL", result);
} catch (UnsupportedEncodingException e) {
// not going to happen - value came from JDK's own StandardCharsets
}
tvDownloadInvoice.setVisibility(View.VISIBLE);
}
LoadingDialog.cancelLoading();
} else if (response.code() == 401) {
callRefreshTokenApi("download");
} else {
LoadingDialog.cancelLoading();
Toast.makeText(getActivity(), response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<DownloadInvoiceModelResponse> call, Throwable t) {
LoadingDialog.cancelLoading();
Toast.makeText(getActivity(), t.toString(), Toast.LENGTH_SHORT).show();
}
});
这里我尝试从以下位置下载文件来自 API 响应的已解码 URL
private void downloadFile() {
getActivity().registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(result));
String title = URLUtil.guessFileName(result, null, null);
request.setTitle(title);
request.setDescription("Downloading file please wait....");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title);
downloadManager = (DownloadManager) `enter code here`getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
Toast.makeText(getActivity(), "Downloading Start", Toast.LENGTH_SHORT).show();
}
This is the URL I am getting from response which is minion encoded
Here I am trying to decode the URL which I got from the API response which is encoded by minio
LoadingDialog.showLoadingDialog(getActivity(), "");
Call<DownloadInvoiceModelResponse> call = TransactionRetrofitClient.getInstance3().getAppApi().downloadInvoice("Bearer " + sharedPrefManager.getBearerToken(), transactionId);
call.enqueue(new Callback<DownloadInvoiceModelResponse>() {
@Override
public void onResponse(Call<DownloadInvoiceModelResponse> call, Response<DownloadInvoiceModelResponse> response) {
if (response.code() == 200) {
if (response.body().getObject()!=null && !response.body().getObject().equals("")){
url = response.body().getObject();
`Trying to decode the URL i am getting from response`
try {
result = URLDecoder.decode(url, "UTF-8");
Log.d("Decoded URL", result);
} catch (UnsupportedEncodingException e) {
// not going to happen - value came from JDK's own StandardCharsets
}
tvDownloadInvoice.setVisibility(View.VISIBLE);
}
LoadingDialog.cancelLoading();
} else if (response.code() == 401) {
callRefreshTokenApi("download");
} else {
LoadingDialog.cancelLoading();
Toast.makeText(getActivity(), response.message(), Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailure(Call<DownloadInvoiceModelResponse> call, Throwable t) {
LoadingDialog.cancelLoading();
Toast.makeText(getActivity(), t.toString(), Toast.LENGTH_SHORT).show();
}
});
Here I am trying to download a file from decoded URL which is coming from the API response
private void downloadFile() {
getActivity().registerReceiver(broadcastReceiver, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(result));
String title = URLUtil.guessFileName(result, null, null);
request.setTitle(title);
request.setDescription("Downloading file please wait....");
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
request.allowScanningByMediaScanner();
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, title);
downloadManager = (DownloadManager) `enter code here`getActivity().getSystemService(Context.DOWNLOAD_SERVICE);
downloadManager.enqueue(request);
Toast.makeText(getActivity(), "Downloading Start", Toast.LENGTH_SHORT).show();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论