How to upload an image from aws using picasso with private access

I am trying to upload an image stored on aws S3 to my Android application using Picasso, but I get an empty image without errors in my logarithm and nothing for me from general debugging around the corresponding lines of code. We have private access to images, so the image URL cannot work in the browser. I need to display an image in my Android application using Picasso. but it does not work.

My code snippet below

  new Picasso.Builder(getApplicationContext()).downloader(new S3Downloader(getApplicationContext(), s3Client, bucket))
                .build()
                .load("https://s3-ea-east-8.amazonaws.com/music/MusicApp_3.jpg")
                .placeholder(R.drawable.img_placeholder)
                .memoryPolicy(MemoryPolicy.NO_CACHE)
                .networkPolicy(NetworkPolicy.NO_CACHE)
                .into(imageView);

When using the above code, the image is displayed only for the first time after installing the application. next time its only display of a placeholder image

I use this library to display an image.

Picasso, "private" url.

+4
3

:

Picasso.with(getApplicationContext()).load(your_url).noFade().into(imageView);
+1
write below code to load image in Picasso. 
variables:-  
String file_path                          -->> this is your image file path 
Imageview mViewHolder.img_post_photo      -->> this is your imageview to load image.
                        Picasso.with(context)
                                .load(file_path)
                                .placeholder(R.mipmap.ic_launcher)
                                .error(R.mipmap.ic_launcher)
                                .into(mViewHolder.img_post_photo, new Callback() {
                                    @Override
                                    public void onSuccess() {

                                    }

                                    @Override
                                    public void onError() {
                                        Picasso.with(context)
                                                .load(file_path)
                                                .placeholder(R.mipmap.ic_launcher)
                                                .error(R.mipmap.ic_launcher)
                                                .into(mViewHolder.img_post_photo);
                                    }
                                });
Set dependencies in your app build.gradle file:-
compile 'com.squareup.picasso:picasso:2.5.2'

hope this code helps you.
+1

You need to create the designated Url from the S3 client, and you can pass this picasso url. This URL will be publicly available and will have an expriy date.

0
source

All Articles