Skip to content

Is there a size limit when saving binary data from Buffer with mongoose-field-encryption? #74

@bluepuma77

Description

@bluepuma77

We would like to save images to MongoDB and want to encrypt the binary data field. And we are aware that the MongoDB object size limit is around 16MB (Stackoverflow info).

But even when the image only has 3.6MB I receive an error with file.save():
ERROR The value of "offset" is out of range. It must be >= 0 && <= 17825792. Received 17825794

// mongoose model
import mongoose from 'mongoose';
const { Schema, model } = mongoose;
import { v4 as uuidv4 } from 'uuid';
import { fieldEncryption } from 'mongoose-field-encryption';

export interface File extends Document {
    id: string,
    blob: Buffer,
    mime: string,
    size: number,
}

const FileSchema = new Schema<File>(
    {
        id: { type: String, required: true, unique: true, index: true, default: () => uuidv4()},
        blob: { type: Buffer },
        mime: { type: String },
        size: { type: Number },
    }
);

FileSchema.plugin(fieldEncryption, { fields: ['blob'], secret: process.env.DB_SECRET });

export default model<File>('Blob', FileSchema);

Is there a specific size limit when saving binary data from Buffer with mongoose-field-encryption?

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions