mongoose-uploader,apollo-upload-server用户的福利
const mongoose = require('mongoose');
const uploaderPlugin = require('mongoose-uploader');
const { createAliOSSUploader } = require('mongoose-uploader-ali-oss');
mongoose.plugin(uploaderPlugin);
const { Schema } = mongoose;
const { File } = Schema.Types;
const ImageUploader = createAliOSSUploader({
bucket: 'your bucket',
region: 'your region',
accessKeyId: 'your key id',
accessKeySecret: 'your secret'
});
const userSchema = new Schema({
avatar: { type: File, uploader: ImageUploader }
});
// Just assign Upload type which is a promise to the doc. It uploads automatically.
const doc = User.create(userGraphQLInput);
doc.save();