업로드 위젯에는 알림 URL을 포함 할 수있는 옵션이 있으며 업로드 사전 설정 설정에서 구성 할 수 있습니다. 이 알림 URL은 이미지 모델을 저장하는 데 사용할 수있는 응답을 서버 끝점으로 반환합니다.
업로드 응답에서 필요한 CloudinaryField를 생성하려면 CloudinaryResource 객체를 사용할 수 있습니다.
from cloudinary import CloudinaryResource
. . .
json_response = { "public_id": "test", "type": "upload", . . . }
# Populate a CloudinaryResource object using the upload response
result = CloudinaryResource(public_id=json_response['public_id'], type=json_response['type'], resource_type=json_response['resource_type'], version=json_response['version'], format=json_response['format'])
str_result = result.get_prep_value() # returns a CloudinaryField string e.g. "image/upload/v123456789/test.png"
# Save the result
p = Photo(title="title",image=str_result)
p.save() # save result in database
"사전"이란 생성 된 숨겨진 입력 필드의 값인 식별자 문자열 또는 POST 요청에 의해 반환 된 JSON 응답을 의미합니까? –
POST 요청에 의해 Cloudinary에 반환되는 값 집합입니다. 나는 그것이 JSON이라고 생각하지만 백엔드로 곧바로 보내고 파이썬은 이것을 사전으로 인식하는 것 같다. 어쩌면 나는 한 걸음 뛸거야? –