I am working on an application that will upload a zip file stored on Amazon S3 through the Heroku Rails server after authentication through oAuth 2. Here's the thread:
- Request for authentication with a server running Heroku through oauth2.
- Get the oAuth2 access token.
- Request to download a zip file from the server (transferring the OAuth token as a medium).
- The server resolves the request and redirects to Amazon S3 a URL containing an expiring signature (to stop downloading content without authentication).
At this point, I want DownloadManager to simply follow the redirection and receive a zip file from S3, however it does not work. Is there any way I can get around this? Or is it just a limitation of DownloadManager?
I am new to Android and still do not fully understand the best debugging methods, so I don’t have a lot of results to show you. However it seems that DownloadManager.COLUMN_STATUS == DownloadManager.STATUS_FAILED and DownloadManager.COLUMN_REASON returns "placeholder"!
EDIT is the code I'm using. Edited to hide the client, etc.
@Override public void onListItemClick(ListView l, View v, int position, long id) { Log.i("ChapterListActivity", "Item clicked: " + id); final DownloadManager downloadManager = (DownloadManager)getSystemService(Context.DOWNLOAD_SERVICE); Uri uri = Uri.parse("http://myapphere.herokuapp.com/api/v1/volumes/2.zip"); DownloadManager.Request request = new Request(uri); String accessToken = getSharedPreferences("keyhere", MODE_PRIVATE).getString("access_token", null); Log.i("SLEChapterListActivity", "Getting file with access token... " + accessToken); request.addRequestHeader("Authorization", "Bearer " + accessToken); long reference = downloadManager.enqueue(request); IntentFilter filter = new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE); BroadcastReceiver receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { long downloadReference = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, -1); Log.i("ChapterListActivity", "Download completed"); Query query = new Query(); query.setFilterById(downloadReference); Cursor cur = downloadManager.query(query); if (cur.moveToFirst()) { int columnIndex = cur.getColumnIndex(DownloadManager.COLUMN_STATUS); if (DownloadManager.STATUS_SUCCESSFUL == cur.getInt(columnIndex)) { String uriString = cur.getString(cur.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); File mFile = new File(Uri.parse(uriString).getPath()); } else if (DownloadManager.STATUS_FAILED == cur.getInt(columnIndex)){ String statusResult = cur.getString(cur.getColumnIndex(DownloadManager.COLUMN_REASON)); Toast.makeText(context, "FAILED " + statusResult, Toast.LENGTH_SHORT).show(); } else if (DownloadManager.ERROR_TOO_MANY_REDIRECTS == cur.getInt(columnIndex)){ String statusResult = cur.getString(cur.getColumnIndex(DownloadManager.COLUMN_REASON)); Toast.makeText(context, "TOO MANY REDIRS " + statusResult, Toast.LENGTH_SHORT).show(); } } } }; registerReceiver(receiver, filter); }
source share