Hi, I got the same problem when I try to integrate with Django
I am working on an EDM with Django. To understand OnlyOffice, I downloaded the ‘Python Example’ version and configured it correctly with Docker. However, when I run it, I get an error message: “The document cannot be saved. Please check connection settings.” Yet, the test version with Docker alone works correctly. Besides this issue, I receive the same message when I integrate it with Django.
- Here below when I was trying to integrate onlyoffice without the Python Example but got the same error
from django.shortcuts import render, get_object_or_404
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
import datetime
import jwt
from .models import Document
from django.conf import settings
import json
def document_list(request):
documents = Document.objects.all()
return render(request, ‘document_list.html’, {‘documents’: documents})
def get_onlyoffice_secret():
return settings.ONLYOFFICE_JWT_SECRET
def generate_onlyoffice_token(payload):
secret = get_onlyoffice_secret()
return jwt.encode(payload, secret, algorithm=‘HS256’)
def open_docx(request, document_id):
document = get_object_or_404(Document, id=document_id)
# Utilisation de request.build_absolute_uri pour s'assurer que l'URL est complète
file_url = request.build_absolute_uri(document.file.url)
print(f"File URL: {file_url}") # Ajouter cette ligne pour vérifier l'URL
document_payload = {
"fileType": document.file.path.split('.')[-1],
"key": str(document.id),
"title": document.title,
"url": file_url,
}
editor_config = {
"mode": "edit",
"callbackUrl": request.build_absolute_uri(f'/documents/callback/{document.id}/')
}
print(f"Callback URL: {request.build_absolute_uri(f'/documents/callback/{document.id}/')}")
payload = {
"type": "desktop",
"document": document_payload,
"editorConfig": editor_config,
"exp": datetime.datetime.utcnow() + datetime.timedelta(hours=1)
}
token = generate_onlyoffice_token(payload)
config = {
"type": "desktop",
"document": document_payload,
"editorConfig": editor_config,
"token": token
}
context = {
"edit_url": f"{settings.ONLYOFFICE_SERVER_URL}/web-apps/apps/api/documents/api.js",
"config": config
}
return render(request, 'edit_docx.html', context)
@csrf_exempt
def onlyoffice_callback(request, document_id):
if request.method == ‘POST’:
Traitez les données de callback ici
data = json.loads(request.body.decode(‘utf-8’))
status = data.get(‘status’, 0)
# Ajoutez votre logique pour traiter les différents statuts ici
if status == 2: # Document Saved
# Sauvegardez le document
pass
return JsonResponse({"error": 0})
return JsonResponse({"error": 1})
Can you help to solve this error ? if possible for both cases.