Answer the question
In order to leave comments, you need to log in
Why the wrong way?
I'm uploading an image.
When sending I get the way
http://localhost:8000/m/Users/ckatala/Desktop/site/backend/media_root/editor_images/139.jpg
http://localhost:8000/m/editor_images/139.jpg
def uploadFile(request):
form = ImageForm(request.POST, request.FILES)
if form.is_valid():
file_ = form.cleaned_data['image']
file_name, extension = os.path.splitext(file_.name)
safe_name = '{0}{1}'.format(slugify(file_name), extension)
name = os.path.join(settings.EDITOR_IMAGE_UPLOAD_PATH, safe_name)
data = dict()
data['path'] = default_storage.save(name, file_)
data['url'] = request.build_absolute_uri(default_storage.url(data['path']))
res = {
"success": 1,
"file": {
"url": data['url']
}
}
else:
res = {
"success": 0,
"file": {
"url": None
}
}
return JsonResponse(res)
MEDIA_URL = '/m/'
EDITOR_IMAGE_UPLOAD_PATH = os.path.join(MEDIA_ROOT, 'editor_images')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media_root')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question