Ejemplo n.º 1
0
 def save_picture_preview(self, instance_id, uploaded_file):
     """
     Get uploaded picture, build thumbnails then save everything in the file
     storage.
     """
     tmp_folder = current_app.config["TMP_DIR"]
     original_tmp_path = thumbnail_utils.save_file(tmp_folder, instance_id,
                                                   uploaded_file)
     file_size = fs.get_file_size(original_tmp_path)
     preview_files_service.update_preview_file(instance_id,
                                               {"file_size": file_size},
                                               silent=True)
     return preview_files_service.save_variants(instance_id,
                                                original_tmp_path)
Ejemplo n.º 2
0
 def save_file_preview(self, instance_id, uploaded_file, extension):
     """
     Get uploaded file then save it in the file storage.
     """
     tmp_folder = current_app.config["TMP_DIR"]
     file_name = instance_id + extension
     file_path = os.path.join(tmp_folder, file_name)
     uploaded_file.save(file_path)
     file_store.add_file("previews", instance_id, file_path)
     file_size = fs.get_file_size(file_path)
     preview_files_service.update_preview_file(instance_id,
                                               {"file_size": file_size},
                                               silent=True)
     os.remove(file_path)
     return file_path
Ejemplo n.º 3
0
def create_attachment(comment, uploaded_file):
    tmp_folder = current_app.config["TMP_DIR"]
    filename = uploaded_file.filename
    mimetype = uploaded_file.mimetype
    extension = fs.get_file_extension(filename)

    attachment_file = AttachmentFile.create(name=filename,
                                            size=0,
                                            extension=extension,
                                            mimetype=mimetype,
                                            comment_id=comment["id"])
    attachment_file_id = str(attachment_file.id)

    tmp_file_path = fs.save_file(tmp_folder, attachment_file_id, uploaded_file)
    size = fs.get_file_size(tmp_file_path)
    attachment_file.update({"size": size})
    file_store.add_file("attachments", attachment_file_id, tmp_file_path)
    return attachment_file.present()