【问题标题】:KeystoneJS edit file before AmazonS3 UploadKeystoneJS 在 AmazonS3 上传之前编辑文件
【发布时间】:2016-07-15 12:56:49
【问题描述】:

如何在 KeystoneJS 文件上传到 AmazonS3 之前对其进行编辑

听起来我应该可以使用下划线方法...但我不知道如何实现它

例如,假设我想在文件上传到 S3 之前将文件转换为 base64 并使用函数完成。如何获取文件,对其应用函数或方法,然后上传。

Model.add({
    file: {         
        type: Types.S3File,
        filename: function(item, filename, originalname){                       
            return "fonts/original/" + item.slug + '.file';
        },

        // ** // ** // ** // ** // ** // ** 
        // Seems like it should go here...
        // On upload EVENT convert file to base64 and upload to S3
        // ** // ** // ** // ** // ** // ** 

    }
});

【问题讨论】:

    标签: javascript node.js express amazon-s3 keystonejs


    【解决方案1】:

    在提交模型之前尝试使用保存事件转换您的图像

    Model.schema.pre('save', function(next) {
       // Your code for convert the image to base 64
        this.imageBase64 = yourEncodedImage
        next();
    });
    

    【讨论】:

    • 这是在正确的轨道上......因为它使事件......但它没有在文件中传递。
    猜你喜欢
    • 2015-08-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-15
    • 2017-03-28
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多