I am building a react native app with Django backend. In the app I let the users upload images which are stored in a models.FileField(). The problem I just noticed is that anyone can access the images from the backend server if they have the right link which raises privacy issues. How would the python and React Native code look like for making sure images that go into can be obtained only with passing a "POST" request which has a "user" and a "token" and how to put those images to be displayed with ? Thank you
React Native with Django backend how to make sure sure that only users with passed token can access images?
78 Views Asked by Itay Lador At
1
There are 1 best solutions below
Related Questions in DJANGO
- Django Admin Panel and Sub URLs Returning 404 Error on Deployment
- How to return HTTP Get request response from models class in Django project
- Issue with Quantity Increment in Django E-commerce Cart
- Can't install Pipenv on Windows
- use dict from python in django html template and also in js
- 'pyodbc.Cursor' object has no attribute 'callproc', mssql with django
- Django socketio process
- Root path analogue in uWSGI as in Uvicorn
- Django - ModuleNotFoundError: No module named 'backend'
- Does Python being a loosely typed programming language make it less secure?
- sorl-thumbnail adds a background color when padding is used
- Can't connect to local postgresql server from my docker container
- Why ProductHunt api dont work with Python?
- why i have to put extra space in before write option selected because it show error if i don't ' option:selected'
- Django Arrayfield migration to cloud sql (Postgresql) not creating the column
Related Questions in REACT-NATIVE
- ussd reader in Recket Native module
- I can't make TextInput to auto expand properly in Android
- expo config plugin use import instead of require
- Custom Sound for Expo Push Notifications Only Works in Foreground
- run RTK dispatch on gesture start with React Native
- Should I set Back-End for my React Native application?
- using infoPlist in app.json for expo project seems to not be working
- Anyone have success configuring react-native-home-indicator?
- KeyboardAvoidingView makes a messy the flexbox
- I am getting lots of errors when building react native app in Xcode
- Search and highlight text of current text in PDFKit Swift
- Flatlist Sometimes Capped at 10 Items Bug
- Is there any way to page transition in react native (stack navigation)
- Screen inside Stack.Navigator not visible in React-Native
- React Native stopwatch implementation slow on iOS
Related Questions in IMAGE
- Golang lambda upload image into s3 static website
- Put an image behind the title in a WP, WooCommerce "shop" page
- How to create an JSOUP element from byte array image (Load from Database)
- Cloudflare not respecting Cache-Control
- Sending multiple images and data in a single angular observable
- Create and combine several images into a single image for my react native App
- Should I compress images in java backend before sending to frontend?
- Javascript Place Image Where User Clicks
- Whitespace in document has a bottom border remnant or some other line at the bottom of the whitespace
- Sony Spresense Camera Board
- After completely installation and done all the work i am getting Permission denied error do any one have solution
- HTML page on NAS server image not showing on mobile phone
- mouse coordinates in image go below 0 and above width
- Why are the css images or js not loading in my laravel project?
- Python pillow library text align center
Related Questions in PRIVACY
- How do I separate emails (from 1 alias) in Thunderbird from invasive websites on Firefox with file browsing scripts? Should I worry?
- Multiple commands produce while adding Target
- Finding out what is using time stamps (privacy manifest required by Apple)
- can a convolutional neural network be reverse engineered?
- Addressing ITMS-91053: Missing API declaration warnings
- Why is Microsoft Visual Studio accessing my microphone?
- How can I disable location information in PHPickerViewController?
- phone call communication between mobile app users
- Privacy Error while launching backend WebAPI Project --
- Need to block adult content from my phone
- Configure amazon s3 privacy policy
- declaring use of userdefaults in the privacy manifest: What is the wrong use of user defaults for iOS 3'rd party library?
- Cordova was listed on the list of requirements for third-party SDKs announced by Apple. How can we get Privacy Manifest file or create it?
- Preventing Screenshots and Screen Recording on Website written in React
- Is an iframe for a HIPAA-compliant form still HIPAA-compliant if the iframe is used on a non-HIPAA-compliant website?
Related Questions in FILEFIELD
- Empty file in thymeleaf after valdiation
- React Native with Django backend how to make sure sure that only users with passed token can access images?
- How to set up a multiple file field on django models?
- How to list all files associated by the employee?
- How to go from pandas.ExcelWriter to models.FileField
- How to use a relative path for Django FileStorage location in migrations?
- Django append to FileField
- Django admin filefield 404 on download
- Why is Django's FileField giving me an encoding error?
- Is it possible to change the status of filefield in admin - DJANGO
- How can I change URL for upladed files?
- path in FileField django
- Save zip to FileField django
- How do I detect if my user has uploaded an ImageField or FileField?
- Display PDF File In Django Templates (FileField)
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Recommended solution
I recommend to use django-private-storage instead.
It specifically designed to serve this purpose. It provides a secure way to handle private files and media uploads in Django, ensuring that only authenticated users have access to them.
Or some alternatives
Serve Images Through Django
Rather than serving files directly, use Django views to serve them. This allows you to implement authentication and permissions on the views.
Let's do it step-by-step.
1. Django URLs:
Let's start by creating the URL pattern to serve your images.
Application's
urls.py:Inside the application's
urls.py, you'll create a URL pattern for the view that serves the image.2. Django View:
Here's a simple Django view that serves the image after checking for user authentication:
3. React Native:
In your React Native application, you would make an authenticated HTTP request to the Django server to get the image. Once you receive the image, you'd display it using the
<Image />component.Here's a basic example using the
fetchAPI:Note that the process uses the Blob API to convert the fetched data into a format that React Native's Image component can use. The
URL.createObjectURLfunction creates a local object URL that you can use as the image source.Do remember that the authentication part (
Authorizationheader in the fetch request) is crucial. You'd typically get the token after a login process and then use it for subsequent requests to your server.This is a simplified example and in a real-world scenario, you might want to handle caching, loading states, and error states in a more comprehensive manner.
Use Secure or One Time URLs
When using cloud providers, you can generate secure, temporary URLs for your files. These URLs will expire after a set amount of time, ensuring that even if someone does get hold of the URL, they won’t have indefinite access.