问题
I'm trying to load image stored on aws S3 into my android app using Picasso but I am getting a blank image with no errors in my logcat and nothing to me from general debugging around the relevant lines of code. We are having private access on images so image url can't work on browser. i need to display image into my android app using Picasso. but it doesn't 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);
By using above code image is displaying only very first time after installing app. next time its only showing placeholder image
I am using this library for displaying image.
The problem isn't with Picasso, it's with loading an image from a "private" url.
please suggest solutions
回答1:
Simply use this:
Picasso.with(getApplicationContext()).load(your_url).noFade().into(imageView);
回答2:
You need to generate a presigned Url from S3 client and you can pass that url to picasso. That url will be public and will have an expriy date.
回答3:
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.
来源:https://stackoverflow.com/questions/46422555/how-to-load-image-from-aws-with-picasso-with-private-access