Is there a way to download a file from an S3 bucket using Android’s DownloadManager?
I can currently download an apk file from Dropbox doing this:
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.addRequestHeader("Content-Type", "application/vnd.android.package-archive"); request.setMimeType("application/vnd.android.package-archive"); final DownloadManager manager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); final long id = manager.enqueue(request);
Now what I want to do is replace “url” with my Amazon URL. When I do this, the download just stays at 0% and just gets stuck there.
Is there any way to do this?
By the way, the Amazon URL I pass in contains the
Signature parameters. The url looks like this:
The reason it fails is because you set the
Content-Type header. This header isn’t needed for HTTP download. However, once set, it has to part of the signature in the presigned URL, as required by AWS S3. Or else you will see 403 Forbidden –
The quick solution is to remove the
Another solution is to generate a presigned URL with headers you need. Say you really want to set content type, you can add it to GeneratePresignedUrlRequest and then create an URL from it.
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucket, key); request.setContentType("application/vnd.android.package-archive"); URL url = s3Client.generatePresignedUrl(request);
See AmazonS3.generatePresignedUrl(GeneratePresignedUrlRequest) for more details.
Hello You can use the following header to get the apk file in request.
Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Cache-Control:no-cache Connection:keep-alive Content-Length:819457 Content-Type:application/octet-stream