1

I have a trouble with using django-rest-framework. I uploaded some videos. And I try to play that videos in react. But I faced 404 error. I added static and media root in setting.py

STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, 'static') MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, "media") 

This is upload code.

 videofile = request.FILES['videoData'] fs = FileSystemStorage() filename = fs.save(videofile.name, videofile) user = request.user File.objects.create( user = user, title = request.data['videotitle'], url = filename, categorys = request.data['categories'], preveimage = request.data['vidoePrevimg'], filetype = request.data['videoType'], filesize = request.data['videoSize'] ) 

It works fine

And in react I tried like this.

<ReactPlayer url={`${baseurl}/media/${videoDetaildata.url}`} playing={true} controls={true} playIcon={true}/> 

This works when the url is Youtube url. Please help me. Thank you in advance.

1 Answer 1

2

During development you have also to append media url and static url to the urlpatterns.

from django.conf import settings from django.conf.urls.static import static urlpatterns = [ # ... the rest of your URLconf goes here ... ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 

Kindly check the following Serving files uploaded by a user during development.
Make sure not to use the above example in production, check the following gist.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.