Video streaming with django API and react-native - django

I'm working on a react-native app witch contains some videos, and when I put in source the uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4', from google samples, it actually works, but if I try to put a uri for a video contained in my django media folder, the following error occur: The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
How can I solve? Thank you

This is because AVFoundation is using byte range requests which is not supported by Django out of the box.
Add this to your middleware: https://github.com/AidenEllis/DjangoRangeMiddleware
Related: Byte Ranges in Django

Related

Django cannot embed a Youtube url in a frame

I am trying to embed a youtube URL into a frame in a Django template. Each time I receive the same message in the console:
Refused to display 'https://www.youtube.com/' in a frame because it set 'X-Frame-Options' to 'sameorigin'.
I have tried inserting two decorators before the view:
#frame_deny_exempt
#xframe_options_exempt
No effect. In a final test I inserted this statement into settings.py just to see if it would turn off the xframe check:
X_FRAME_OPTIONS = 'ALLOWALL'
The same error appears.
I also tried removing the XFrameOptions middleware, no change.
This is in a local testing environment so I am using the Django web server, my production server (which I have not tried moving this to for obvious reasons) is an Azure instance running NGINX
Are you using an embeddable URL?
https://support.google.com/youtube/answer/171780
It is YouTube that is providing the X-Frame-Options header that the browser is complaining about, which implies you are trying to embed the normal URL to the video.

Video streaming in react-native using custom API

I'm working on a react-native app using expo-av to show videos, and whne I put in source the uri: 'http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4', from google samples, it acutally works, but if I try to put a uri for a video contained in my django media folder, the following error occur:
The server is not correctly configured. - The AVPlayerItem instance has failed with the error code -11850 and domain "AVFoundationErrorDomain".
How can I solve?
Thank you

Rendering images from REST response on localhost

I am trying to run a REST API on one port (8000) using django and consuming that API in an App running on port 9000 again using django.
My REST response is having an image field, now the problem is that i can not provide my desktop path in upload_to option in my API models and if i am giving the absolute path of API project in my App project index. Html, i get a browser error as "Not allowed to load resources from local path"
So i am having to create media folders with same name in both API and App projects and keeping image files in both and using only the file path from the REST response and rendering the image from App project itself.
Is there any way i can get away with this and consume the image from the Rest response only?
You need to convert image to base64 in server side then send those base64 string as response . Then consume this base64 string as response in calling api. Then use it accordingly either save in filesysyem or in database . But make sure to converse base 64 image string to bytes.

Why is GET and POST request converting to OPTIONS request for cross-origin request for django rest framework and reactjs frontend?

I was looking to run my django and reactjs web application on mobile by connecting it to mac via hotspot, and changing the host to the ipaddress of the mobile. Thus, I changed my localhost to 192.168.43.19 in /etc/hosts/, and thus, my code is easily shared between mobile and mac, and I am able to run the localhost app on my mobile which is connected to mac via hotspot.
The backend is created in django rest framework. The problem is that all the get and post calls to the api created in the backend in django is being converted to options calls, and thus there are no returns, and the code is not working properly. While searching online, it said that the issue is because by default Access-cross-origin-policy is not allowed. To try handling the issue, I added the frontend url in CORS_ORIGIN_WHITELIST in the settings file of the django app, but it didnt work.
The CORS_ORIGIN_WHITELIST value set is the one, where the react code is being run. It is
CORS_ORIGIN_WHITELIST = (
'http://192.168.43.194:3000',
)
It will be really helpful, if someone could recommend me the correct way to handle this?

Upload image to Swift from Django Rest Framework

I have a problem related with uploading images directly to object storage Swift, using Django Rest Framework.
Most of tutorials present simple upload images to /media/ directory in localhost, but this option is not going to fit in my project.
Tried use django-storage-swift - https://github.com/blacktorn/django-storage-swift . While doing requests using httpie, I received in 50% of requests an error:
requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:600)
[06/Jun/2017 13:03:01] "POST /api/processing_raw_files/ HTTP/1.1" 500 24946
This makes, that only half of uploading files will be in fact sending to the cloud.
I am working on
Ubuntu 14.04
Python 3.4.3
Django 1.11
djangorestframework 3.6.2
django-storage-swift 1.2.16
Do you know any other possibility how can I upload images using swift and django rest? Or did you face with ssl error utilizing django-storage-swift?