0

在我的 Android 应用程序中,我必须从亚马逊存储桶下载视频。当我尝试从亚马逊存储桶下载视频时,一段时间后它会出现错误

06-16 12:01:55.792: I/System.out(577): ERROR in Thread : java.io.IOException: null SSL pointer

这里是从 Amazon s3 存储桶下载视频的代码

public class AmazonS3Helper 
{
GeneralHelper objHelper;
Context myContext;
String bucketName;
String accessKey;
String secretKey;

ProgressBar myProgressBar;

AWSCredentials credential;

int len;
int total = 0;

public AmazonS3Helper(Context context,List list)
{
    try
    {
        myContext = context;
        objHelper = new GeneralHelper(myContext);

        bucketName = "mybucketName";
        accessKey = "myaccesskey";
        secretKey = "mysecretkey";

        credential = new BasicAWSCredentials(accessKey, secretKey);

        getFileFromAmazonS3(list);
    }
    catch (Exception ex) 
    {
        System.out.println("ERROR : "+ex.toString());
    }
}

public AmazonS3Helper(Context context,String amazonObjectName,ProgressBar progress)
{
    try
    {
        myContext = context;
        objHelper = new GeneralHelper(myContext);
        //progressBar = progress;

        bucketName = "mybucketname";
        accessKey = "key";
        secretKey = "key";

        credential = new BasicAWSCredentials(accessKey, secretKey);

        getFileFromAmazonS3(amazonObjectName,progress);
    }
    catch (Exception ex) 
    {
        System.out.println("ERROR : "+ex.toString());
    }
}

public void getFileFromAmazonS3(List list)
{
    try
    {
        List<DownloadItemList> downloadList = list;

        List<S3Object> s3ObjectList = new ArrayList<S3Object>();

        for(int i=0;i<downloadList.size();i++)
        {
            DownloadItemList downloadItem = downloadList.get(i);

            String objectImageKey = downloadItem.getEncryptName()+".app/"+downloadItem.getImageName();
            String objectAudioKey = downloadItem.getEncryptName()+".app/"+downloadItem.getAudioName();

            GetObjectRequest objRequest = new GetObjectRequest(bucketName,objectImageKey);
            AmazonS3Client myS3Client = new AmazonS3Client(credential);
            S3Object s3Object = myS3Client.getObject(objRequest);

            s3ObjectList.add(s3Object);             

            objRequest = new GetObjectRequest(bucketName,objectImageKey);
            myS3Client = new AmazonS3Client(credential);
            s3Object = myS3Client.getObject(objRequest);

            s3ObjectList.add(s3Object);
        }
    }
    catch (Exception ex) 
    {
        System.out.println("ERROR : "+ex.toString());
    }
}


// For Video
public void getFileFromAmazonS3(String strObjectName,ProgressBar progress)
{
    try
    {   
                    String md5Name = objHelper.getMD5HasCode(strObjectName);

        String strObjectKey = "video path";

        GetObjectRequest objRequest = new GetObjectRequest(bucketName,strObjectKey);

        AmazonS3Client myS3Client = new AmazonS3Client(credential);

        S3Object s3Object = myS3Client.getObject(objRequest);

        String filePath = strObjectName+"_video.mp4";

        System.out.println("OK - 8");

        downloadObject(s3Object,filePath,progress);         


    }
    catch (Exception ex) 
    {
        System.out.println("ERROR : "+ex.toString());
    }
}

private void downloadObject(S3Object s3Object,String path,ProgressBar progress)
{
    try
    {
        myProgressBar = progress;

        System.out.println("OK - 8");

        String filePath = objHelper.getFullFilePath(path); // + "noha_video1.mp4";

        System.out.println("FilePath : "+filePath);

        final long fileSize = s3Object.getObjectMetadata().getContentLength();
        final InputStream input = s3Object.getObjectContent();
        final FileOutputStream fos = new FileOutputStream(filePath);

        myProgressBar.setMax((int) fileSize);

        System.out.println("Input Stream Length : " + fileSize);

        final byte[] buf = new byte[1024];

        Thread thread = new Thread()
        {
            public void run()
            {
                try
                {
                    total = 0;

                    while((len = input.read(buf)) > 0)
                    {
                        fos.write(buf,0,len);

                        total = total + len;

                        Message msg = handler.obtainMessage();
                        Bundle b = new Bundle();
                        b.putInt("total", total);
                        msg.setData(b);
                        handler.sendMessage(msg);

                    }
                    if(len == -1 && total==Integer.parseInt(String.valueOf(fileSize)))
                    {
                        Thread.currentThread().interrupt();

                        input.close();
                        fos.close();

                        objHelper.startTargetActivity(myContext, VideoActivity.class);
                    }
                }
                catch (Exception ex) 
                {
                    System.out.println("ERROR in Thread : "+ex.toString());
                }
            }
        };

        thread.start();
    }
    catch (Exception ex) 
    {
        System.out.println("ERROR in Run Thread : "+ex.toString());
    }
}

Handler handler=new Handler() 
{

    @Override

    public void handleMessage(Message msg) 
    {
        myProgressBar.setProgress(msg.getData().getInt("total"));

    }

};

}

4

1 回答 1

0

您能否检查最终为获取文件生成的 URL,将相同的 URL 粘贴到浏览器中并检查天气,'http'有时'https'当您发布时'http'它会转换为'https'如果是,'https'那么您必须获取证书。

于 2012-06-16T13:19:12.987 回答