简体   繁体   English

无法在Android电脑上下载文件,而在PC上下载确定(亚马逊)

[英]Could'nt download file on Android while on PC it downloads ok (amazon)

Got an weird issue. 有一个奇怪的问题。 A file with Url: https://s3.amazonaws.com/myappdata/msg/171401089927.mp3 (not available any more) downloads ok on PC and its mp3 file. 网址为https://s3.amazonaws.com/myappdata/msg/171401089927.mp3的文件(不再可用)可以在PC及其mp3文件上正常下载。 But when I try to DL it on Android FOA Im getting content-type "application/xml" instead of "audio/mpeg" and when downloading starts I'm getting: 但是,当我尝试在Android FOA上对其进行DL下载时,我得到的是内容类型“ application / xml”而不是“ audio / mpeg”,并且在开始下载时,我得到了:

05-30 12:13:44.478: E/PlayerService(28023): java.io.FileNotFoundException: https://s3.amazonaws.com/myappdata/msg/171401089927.mp3
05-30 12:13:44.478: E/PlayerService(28023):     at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
05-30 12:13:44.478: E/PlayerService(28023):     at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)

The code used to DL: 用于DL的代码:

    /**
     * Download the url stream to a temporary location
     */
    public void downloadAudioIncrement(String mediaUrl) throws IOException {
        Log.i(TAG, "downloadAudioIncrement(): mediaUrl: "+mediaUrl+"\ncacheDir: "+cacheDir);

        URL url = null;

        try {
            url = new URL(mediaUrl);
        } catch (MalformedURLException e) {
            e.printStackTrace();
            throw new IOException("Unable to create InputStream for mediaUrl:" + mediaUrl);
        }

        // this file will represent whole downloaded song
        mp3FileDownloaded = new File(cacheDir, mp3FileName);
        if (!mp3FileDownloaded.exists())
            //FileUtils.makeDirsForFile(mp3FileDownloaded);
            try{
                mp3FileDownloaded.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
        }

        if (!mp3FileDownloaded.canWrite())
            throw new IOException("Can't open temporary file for writing");

        HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();

        urlConnection.setReadTimeout(1000 * 20);
        urlConnection.setConnectTimeout(1000 * 5);

        urlConnection.setDoInput(true);
        urlConnection.setDoOutput(true);

        int mp3BytesSize = urlConnection.getContentLength();
        // final String
        // contentLengthStr=urlConnection.getHeaderField("content-length");

        String ctype = urlConnection.getContentType();
        if (ctype == null) {
            ctype = "";
        } else {
            ctype = ctype.toLowerCase(Locale.US);
        }
        // See if we can handle this type
        Log.i(TAG, "Content Type: " + ctype);

        if ( ctype.contains("audio/mpeg") || TextUtils.isEmpty(ctype) ) {

            String temp = urlConnection.getHeaderField(BITRATE_HEADER);
            Log.i(TAG, "Bitrate: " + temp);
            // if (temp != null){
            // bitrate = new Integer(temp).intValue();
            // }
        } else {
            Log.e(TAG, UNSUPPORTED_AUDIO_TYPE+": " + ctype);
//          throw new IOException(UNSUPPORTED_AUDIO_TYPE+": " + ctype);
            // Log.e(TAG, "Or we could not connect to audio");
            // stop();
            // return;
        }
        final InputStream stream = new BufferedInputStream(urlConnection.getInputStream(),8192);
...

Right at the last shown line of code (instantiating the InputStream stream) the mentioned IOExeption raised. 在最后显示的代码行(实例化InputStream流)的右边,提到了IOExeption。 There are other mp3 files exists at same location and they are downloading with no any issue but only mentioned above url fails. 在相同位置还存在其他mp3文件,它们正在下载,没有任何问题,但仅上述url失败。
What could be wrong here? 这有什么问题吗?
UPDATE UPDATE
Its appears that this issue happens on HTC Rezound with AOS 4.0.4. 看来此问题发生在带有AOS 4.0.4的HTC Rezound上。 On other device, with AOS 2.3.5 everything works ok. 在其他设备上,使用AOS 2.3.5,一切正常。

seems like the line 似乎像线

urlConnection.setDoOutput(true);

was the source of issue since I don't upload any data. 是问题的根源,因为我没有上传任何数据。 Everything works fine since I'd comment it. 一切正常,因为我会发表评论。 Also these FileNotFoundException while getting the InputStream object from HttpURLConnection and Android HttpUrlConnection getInputStream throws NullPointerException threads might be helpfull. 同样,在从HttpURLConnectionAndroid HttpUrlConnection 获取InputStream对象时,这些FileNotFoundException 抛出NullPointerException线程可能也会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将文件下载到Android中的内部下载文件夹中 - How to download file into internal downloads folder in Android 使用Android下载提供程序进行文件下载 - File download using Android downloads provider Android 在从 PC 中查找文件时未在“下载”文件夹中显示文件 - Android does not show file in Downloads folder when looking for it from PC android,directory_downloads 中的下载文件是否需要危险权限? - android, download file in directory_downloads need dangerous permission or not? 使用phonegap下载文件到下载文件夹ios / android - Download file to downloads folder ios/android using phonegap 如何将文件下载到我的下载文件夹android - How can I download a file to my downloads folder android Android ftp下载无法正确下载文件 - Android ftp download doesn't downloads file properly 从Android应用程序将文件上传并下载到Amazon - Upload and download file to Amazon from android application 在使用 Android Kotlin 创建 Android 应用程序时,无法正常显示 Z1D78DC8ED51214E518B5114FEZ4,尽管 App 工作正常, - While creating the Android Application using Android Kotlin, could'nt display map, even though the App is working normally 在PC上下载Android ISO - Download Android ISO on PC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM