mongoose-uploader,apollo-upload-server用户的福利
发布于 1 个月前 作者 cheunghy 286 次浏览 来自 分享
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();
回到顶部