Giter VIP home page Giter VIP logo

Comments (8)

SoMCUSDev avatar SoMCUSDev commented on August 15, 2024 3

This could be because you have . (dot) as part of the bucket name. One of the advices is to use '-' instead of '.' in S3 bucket names that will be accessed via HTTPS.

from aws-sdk-android.

rahulgautam avatar rahulgautam commented on August 15, 2024

For refrence this my code snippet

        Picasso.Builder builder = new Picasso.Builder(this);
        Picasso picasso = builder.downloader(new OkHttpDownloader(this) {
            @Override
            protected HttpURLConnection openConnection(Uri uri) throws IOException {
                // get bucket name and filename (key) from uri (https://s3.amazonaws.com/BUCKET_NAME/FILENAME.JPG)
                 String BUCKET_NAME;
                 URL url = sS3Client.generatePresignedUrl("<BUCKET_NAME>", "<FILENAME>", nowPlus10Minutes.getTime());
                 HttpURLConnection connection =null;
                try {
                    connection = super.openConnection(Uri.parse(url.toString()));
                    Log.v(" === connection.getURL()", connection.getURL().toString());
                }
                catch (Exception e){
                    Log.v( "Exception occured ", "picasso openConnection");
                }
                return connection;
            }
        }).build();
        picasso.setLoggingEnabled(true);

        picasso.load("https://s3.amazonaws.com/BUCKET_NAME/FILENAME.JPG").into(imageView,new Callback() {
            @Override
            public void onSuccess() {
                Log.v("-------","success");
            }

            @Override
            public void onError() {
                Log.v("--------","error");
            }
        });

Appriciate any help,
Thanks

cc @Synderesis @wdane

from aws-sdk-android.

wdane avatar wdane commented on August 15, 2024

I'm sorry your having trouble rahulgautam. Unfortunately I cannot seem to reproduce the issue. I've tried generating a pre-signed URL and the image opens fine in Firefox/Chrome/Safari as well as on the emulator browser and I am also able to download it fine. The code I used to test is below. Let me know if you can't get this to work for you.

class testPresignedURL extends AsyncTask<Void,Void,Void>{

    @Override
    protected Void doInBackground(Void... params) {
        Calendar tomorrow = Calendar.getInstance();
        tomorrow.add(Calendar.HOUR, 24);
        Date td = tomorrow.getTime();

        URL url = s3Client.generatePresignedUrl(YOUR_BUCKET, YOUR_IMAGE, td);
        Log.d(TAG,"URL is: "+url.toString());

//Uncomment code below to see in phone's browser
// Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url.toString()));
// startActivity(browserIntent);

        File storagePath = new File(Environment
                .getExternalStorageDirectory()
                + "/testpresignedurl/images/");
        storagePath.mkdirs();
        File file = new File(storagePath, YOUR_FILE);  

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

        urlConnection.setRequestMethod("GET");
        urlConnection.connect();
        FileOutputStream fileOutput = new FileOutputStream(file);
        InputStream inputStream = urlConnection.getInputStream();
        int downloadedSize = 0;

        byte[] buffer = new byte[1024];
        int bufferLength = 0;
        while ((bufferLength = inputStream.read(buffer)) > 0) {
            fileOutput.write(buffer, 0, bufferLength);
            downloadedSize += bufferLength;
            Log.d(TAG,"downloaded chunk total: "+downloadedSize);
        }

        fileOutput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Weston

from aws-sdk-android.

rahulgautam avatar rahulgautam commented on August 15, 2024

Hi @wdane,
Thanks for reply and code-snippet,

When I open the URL generated by presignedURL, same thing happened.
download

Although image gets download through asynctask (code snippet you provide).

Now a days there is new issue with SSL (poodle etc), is something related to this, because I still have not figure out what causing this behaviour.

from aws-sdk-android.

richardfung avatar richardfung commented on August 15, 2024

Can you show is what the actual URL is? Also what is your development environment like? If you are using a packet sniffer that could cause issues.

Have you tried accessing the URL from a different device? Maybe on a different network? That might help narrow down the source of the issue

from aws-sdk-android.

rahulgautam avatar rahulgautam commented on August 15, 2024

Yes I do have . (dot) as part of bucket name, I could not share the exact URL but this is how it looks
https://my.bucket.name.s3.amazonaws.com/0076bb56-32qc-11d4-90da-0ac2f0fa92c6_1410249846.047449.JPG?AWSAccessKeyId=ACCESS93NPP3OW4IQWER&Expires=1414587123&Signature=byIJwcjtcZ9bW%2F2O8i%2FdsprvsOM%3D

I am not using any packet sniffer, development enviourment is Mac OS X Yosemite and private optical network infrastructure.

from aws-sdk-android.

rahulgautam avatar rahulgautam commented on August 15, 2024

Hi @SoMCUSDev Thanks for your help man, removing . from my bucket name worked for me.

AWS Console should mention this information when a user creates a bucket. that would save all this trouble to users.

Thanks guys for all your help

from aws-sdk-android.

wdane avatar wdane commented on August 15, 2024

Thanks Rahulgautam, let us know if you have any further issues!

from aws-sdk-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.