Getting image from Django on AWS, to Android Glide. 404 error -


i implemented rest api using django-rest-framework, deployed aws-ec2.

settings.py

media_url = '/images/' media_root = os.path.join(base_dir, 'images') 

serializers.py

class postserializer(serializers.modelserializer):     author = serializers.readonlyfield(source='author.username')     class meta:         model = post         fields = ('author', 'text', 'image')     def create(self, validated_data):         validated_data['author'] = self.context['request'].user         return super(postserializer, self).create(validated_data) 

urls.py

router = simplerouter() router.register(r'posts', views.postviewset, base_name='posts') urlpatterns = router.urls  urlpatterns = [     url(r'^', include(router.urls)),     ] 

views.py

class postviewset(viewsets.modelviewset):     serializer_class = postserializer     permission_classes = [isauthenticated]     queryset = post.objects.all() 

so, returned:

  {     "author": "ghdalsrn",     "text": "11",     "image": "http://ec2-52-78-138-143.ap-northeast-2.compute.amazonaws.com:8000/images/images/avril_lavigne_-_00_-_sk8er_girl_-_frontcover_-simplemp3s.jpg"   } 

i used "image": "http://ec2-52-78-138-143.ap-northeast-2.compute.amazonaws.com:8000/images/images/avril_lavigne_-_00_-_sk8er_girl_-_frontcover_-simplemp3s.jpg" on android studio.

android mainactivity.java

public class mainactivity extends appcompatactivity {      public imageview mimage;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          mimage = (imageview) findviewbyid(r.id.iv_image);          glide.with(this)                 .load("http://ec2-52-78-138-143.ap-northeast-2.compute.amazonaws.com:8000/images/images/avril_lavigne_-_00_-_sk8er_girl_-_frontcover_-simplemp3s.jpg")                 .centercrop()                 .into(mimage); 

but, according putty message,

putty

"get /images/images/filename_sk8er_girl.jpg http/1.1" 404 5184

also android application doesn't show image.

how fix ?

your folder structure in server wrong. according this should put static files under structure this:

[home folder manage.py located]/[module_name]/[images, defined in settings.py]/[module_name]/[image_file_name] 

in case:

new/mymodule/images/mymodule/avril_lavigne_-_00_‌​-_sk8er_girl_-_front‌​cover_-simplemp3s.jp‌​g 

double check folder structures. may have update file paths in database.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -