def create_new_attachment(paste_id, file_name, file_size, mime_type, file_data):
"""
Create a new database entry for an attachment with the given file_name, associated with a particular paste ID.
:param paste_id: Paste ID to associate with this attachment
:param file_name: Raw name of the file
:param file_size: Size of the file in bytes
:param mime_type: MIME type of the file
:param file_data: Binary, base64-encoded file data
:return: An instance of models.Attachment describing this attachment entry
:raises PasteDoesNotExistException: If the associated paste does not exist
"""
# Add an entry into the database describing this file
new_attachment = models.Attachment(
paste_id=paste_id,
file_name=secure_filename(file_name),
file_size=file_size,
mime_type=mime_type,
)
_store_attachment_file(paste_id, file_data, new_attachment.hash_name)
session.add(new_attachment)
session.commit()
return new_attachment
评论列表
文章目录