25๐
โ
The error is happening because the function handle_uploaded_file(f)
is trying to open an already opened file.
The value of request.FILES['file']
is a InMemoryUploadedFile
and can be used like a normal file. You donโt need to open it again.
To fix, just remove the line that tries to open the file:
def handle_uploaded_file(f):
for x in f:
if x.startswith('newick;'):
print('')
return cutFile(x)
๐คWill Keeling
1๐
the solution for me;
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
instead of :
MEDIA_ROOT = [os.path.join(BASE_DIR, 'media')]
in settigs.py
๐คDeniz
- Django Channels Error โ Cannot import BACKEND 'asgi_redis.RedisChannelLayer'
- Can't git-push to heroku due to "Build stream timed out"
- Filter a django QuerySet with the query from another QuerySet: Possible?
- How to move model to the other section in Django's site admin
0๐
In my setting.py I had
MEDIA_ROOT = os.path.join(BASE_DIR, 'media'),
when it shouldโve been
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
which solved this error for me.
๐คRichard E Long
- Does Django use processes or threads to handle user requests in view?
- Change row colour in Django Admin List
- Django queryset order_by dates near today
- ValidationError while using ModelForm Django
0๐
Save the InMemoryUploadedFile to a temporary file.
you can save the InMemoryUploadedFile to a temporary file and then read the data from that file.
import tempfile
if input:
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
temp_file.write(input.read())
temp_file.close()
with open(temp_file.name, 'r') as file:
image_data = file.read()
๐คPooja
- How to Paginate within an action in Django Rest Framework
- How could one disable new account creation with django-allauth, but still allow existing users to sign in?
Source:stackexchange.com