Creates new content with file upload. This endpoint requires admin authentication and accepts multipart/form-data for file uploads.
This endpoint requires admin authentication. Include a valid JWT token in the Authorization header: Bearer <token>
Bearer token for admin authentication
Must be multipart/form-data
Request Body (multipart/form-data)
Content type. Must be one of: pdf, video, audio
Content price (minimum: 0)
The content file to upload (PDF, video, or audio file)
Optional thumbnail image for the content
Content status. Must be one of: draft, published
JSON stringified array of tags. Example: ["javascript", "advanced"]
Response
Created content object Unique identifier for the content
Content type: pdf, video, or audio
Cloudinary URL to the uploaded file
Cloudinary public ID for the file
Cloudinary URL to the thumbnail image
Cloudinary public ID for the thumbnail
Duration in seconds (for video/audio content)
Creator information with name and email
Error Responses
400 Bad Request
{
"error" : "Content file is required"
}
401 Unauthorized
Returned when authentication token is missing or invalid.
403 Forbidden
Returned when the authenticated user is not an admin.
500 Internal Server Error
{
"error" : "Error message"
}
Files are uploaded to Cloudinary. The fileUrl and filePublicId are automatically generated and stored. The duration field is automatically populated for video/audio files, and fileSize is captured in bytes.
{
"message" : "Content created successfully" ,
"content" : {
"_id" : "507f1f77bcf86cd799439011" ,
"title" : "Advanced JavaScript Patterns" ,
"description" : "Learn advanced design patterns in JavaScript" ,
"type" : "pdf" ,
"category" : "507f1f77bcf86cd799439012" ,
"price" : 29.99 ,
"fileUrl" : "https://res.cloudinary.com/example/raw/upload/v1234567890/content.pdf" ,
"filePublicId" : "vaniyk/content/abc123" ,
"thumbnailUrl" : "https://res.cloudinary.com/example/image/upload/v1234567890/thumbnail.jpg" ,
"thumbnailPublicId" : "vaniyk/thumbnails/xyz789" ,
"fileSize" : 5242880 ,
"status" : "draft" ,
"tags" : [ "javascript" , "patterns" , "advanced" ],
"createdBy" : {
"_id" : "507f1f77bcf86cd799439013" ,
"name" : "John Doe" ,
"email" : "[email protected] "
},
"createdAt" : "2024-03-01T12:00:00.000Z" ,
"updatedAt" : "2024-03-01T12:00:00.000Z"
}
}