Skip to content

Instantly share code, notes, and snippets.

@NickyAlan
Created April 19, 2022 15:53
Show Gist options
  • Save NickyAlan/77a66bf135c9be1bac9f2c12e7d73234 to your computer and use it in GitHub Desktop.
Save NickyAlan/77a66bf135c9be1bac9f2c12e7d73234 to your computer and use it in GitHub Desktop.
crete media folder with piority same as static folder
[settings.py]
import os
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
[urls.py] at main project
from django.conf import settings
from django.conf.urls.static import static
if settings.DEBUG :
urlpatterns += static(settings.MEDIA_URL, root=settings.MEDIA_ROOT)
[html]
<form method="POST" enctype="multipart/form-data">
{% csrf_token %}
<input type='file' name="fileName">
<button type="submit">Upload</button>
</form>
[views.py]
if request.method == 'POST' :
try :
data = request.POST.copy()
except :
return render(request,'app/speechtotext.html')
file = request.FILES['fileName']
fs = FileSystemStorage()
fs.save(flie.name,file)
...open(media/speech_data.wav)...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment