提问者:小点点

base64映像无法保存在mongoDB中


我使用angular在我的nodejs后端发送不同的数据,并将它们保存在MongoDB中。 我的问题是当我保存base64映像时。 当base64较短时(30kB),它是好的,但当我试图保存更高的映像时(100kB),我会出现以下错误:

CORS策略已阻止从起源“http://localhost:8100”访问“http://localhost:3000/cdirectories/”处的XMLHttpRequest:请求的资源上不存在“Access-Control-Allow-Origin”标头:

app.use((req, res, next) => {
    res.header('Access-Control-Allow-Origin', '*'),
    res.header(
        'Access-Control-Allow-Headers',
        'Origin, X-Requested-With, Content-Type, Accept, Authorization'
        );
    if (req.method === 'OPTIONS') {
        res.header('Access-Control-Allow-Methods', 'PUT, POST, PATCH, DELETE, GET');
        return res.status(200).json({});
    }
    next();
});

我尝试在Blob上转换此图像,但无法找到如何在mongodb中添加type:Blob:

const cdirectorySchema = mongoose.Schema({
    _id: mongoose.Schema.Types.ObjectId,
    cdirectoryId: {type: String},

谢谢你的帮助,对不起我的英语


共1个答案

匿名用户

您使用的是body-parser吗? 如果是,选中limit选项,它设置最大请求体大小,默认值为100KB,您可以将其设置为更大的数字,如'10MB'