我已经按照亚马逊指南,将文件上传到Amazon S3,我注意到这太慢了.上传一个简单的png文件约20kb需要大约10秒.
最初我以为这个问题与线程有关,我已经实现了一个AsyncTask来上传图像,但问题依然存在.以下是用于上传图像的代码.
private class UploadFileTask extends AsyncTask<String,Integer,String> { String remotePath; String remoteFileName; File file; Context context; S3UploadInterface listener; public UploadFileTask(Context context,String remotePath,String remoteFileName,File file,S3UploadInterface listener){ this.context=context; this.remotePath=remotePath; this.remoteFileName=remoteFileName; this.file=file; this.listener=listener; } protected String doInBackground(String... params) { credentialsProvider = new CognitoCachingCredentialsProvider(context,"MY_PRIVATE_CREDENTIAL",Regions.US_EAST_1); TransferManager transferManager = new TransferManager(credentialsProvider); Upload upload = transferManager.upload(remotePath,remoteFileName,file); TransferProgress transferred = upload.getProgress(); while (!upload.isDone()) { try { publishProgress((int) transferred.getPercentTransferred()); } catch (Exception e) { listener.uploadFailed(e); } } return "uploaded"; } protected void onProgressUpdate(Integer... progress) { if (listener!=null) listener.currentUploadProgress(progress[0]); } protected void onPostExecute(String result) { if (listener!=null) listener.uploadCompleted(); } }
有什么想法来解决这个问题吗?
谢谢 :)