I am using django-ckeditor for users to enter rich text on my site's webpages.Every webpage on my site represents a document with a unique id.
For ex- two separate documents will have two web pages with URLs such as -
example.com/documents/doc1 and example.com/documents/doc2
Each of these 2 web pages have multiple CKEDITORs.I want that when user uploads image through CKEDITORs on webpage- example.com/documents/doc1 should go to a separate directory
/media/uploads/doc1/
and images uploaded through CKEDITORs on webpage example.com/documents/doc2 should go to a separate directory -
/media/uploads/doc2/
Now the problem arises here.In the upload view method in views.py of django-ckeditor module -
def post(self, request, **kwargs):
"""
Uploads a file and send back its URL to CKEditor.
"""
# Get the uploaded file from request.
upload = request.FILES['upload']
#Verify that file is a valid image
backend = image_processing.get_backend()
try:
backend.image_verify(upload)
except utils.NotAnImageException:
return HttpResponse("""
<script type='text/javascript'>
alert('Invalid image')
window.parent.CKEDITOR.tools.callFunction({0});
</script>""".format(request.GET['CKEditorFuncNum']))
# Open output file in which to store upload.
upload_filename = get_upload_filename(upload.name, request.user)
saved_path = default_storage.save(upload_filename, upload)
if backend.should_create_thumbnail(saved_path):
backend.create_thumbnail(saved_path)
url = utils.get_media_url(saved_path)
# Respond with Javascript sending ckeditor upload url.
return HttpResponse("""
<script type='text/javascript'>
window.parent.CKEDITOR.tools.callFunction({0}, '{1}');
</script>""".format(request.GET['CKEditorFuncNum'], url))
upload_filename is defined as get_upload_filename(upload.name,request.user)
It takes filename and request.user as parameters and stores files in user specific folders.How can I pass the docid from my url to the post request so that I can use docid to store images in the document-centric folders?
I hope my point is understood.If any more information is needed then please let me know in the comments, I would add those. Thanks
将其添加到config.filebrowserUploadUrl中:
config.filebrowserUploadUrl = "/upload.php?docid=" + docid;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.