如何从 minio 服务器 URL 下载文件

发布于 2025-01-14 21:33:56 字数 3268 浏览 0 评论 0原文

这是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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文