Я пытаюсь понять, как взять изображение (файл с помощью CollectionFS) и вставить идентификатор изображения в поле Мои элементы imageId
:
Библиотека/Коллекции/items.js
Items = new Mongo.Collection("items");
Items.attachSchema(new SimpleSchema({
name: {
type: String,
label: "Name",
},
userId: {
type: String,
regEx: SimpleSchema.RegEx.Id,
autoform: {
type: "hidden",
label: false
},
autoValue: function () { return Meteor.userId() },
},
image: {
type: String,
optional: true,
autoform: {
label: false,
afFieldInput: {
type: "fileUpload",
collection: "Images",
label: 'Select Photo',
}
}
},
imageId: {
type: String
}
}));
Библиотека/Коллекции/images.js
if (Meteor.isServer) {
var imageStore = new FS.Store.S3("images", {
accessKeyId: Meteor.settings.AWSAccessKeyId,
secretAccessKey: Meteor.settings.AWSSecretAccessKey,
bucket: Meteor.settings.AWSBucket,
});
Images = new FS.Collection("Images", {
stores: [imageStore],
filter: {
allow: {
contentTypes: ['image/*']
}
}
});
}
// On the client just create a generic FS Store as don't have
// access (or want access) to S3 settings on client
if (Meteor.isClient) {
var imageStore = new FS.Store.S3("images");
Images = new FS.Collection("Images", {
stores: [imageStore],
filter: {
allow: {
contentTypes: ['image/*']
},
}
});
}
Сейчас мои правила разрешений:
сервер/allows.js
Items.allow({
insert: function(userId, doc){return doc && doc.userId === userId;},
update: function(userId, doc){ return doc && doc.userId === userId;},
remove: function(userId, doc) { return doc && doc.userId === userId;},
})
Images.allow({
insert: function(userId, doc) { return true; },
update: function(userId,doc) { return true; },
remove: function(userId,doc) { return true; },
download: function(userId, doc) {return true;},
});
Я использую Autoform, поэтому моя форма выглядит следующим образом:
клиент/item_form.html
<template name="insertItemForm">
{{#autoForm collection="Items" id="insertItemForm" type="insert"}}
{{> afQuickField name="name" autocomplete="off"}}
{{> afQuickField name="image" id="imageFile"}}
<button type="submit">Continue</button>
{{/autoForm}}
</template>
Прямо сейчас, когда я выбираю просмотр и выбираю образ, он будет находиться в базе данных, и я хочу принять его _id
и разместить его в Item
, который создается впоследствии, но как я могу получить этот конкретный образ? Я понял, что это хороший способ ссылки на изображение.
ОБНОВЛЕНИЕ 1
Выясните, что идентификатор на самом деле скрыт после выбора файла:
<input type="hidden" class="js-value" data-schema-key="image" value="ma633fFpKHYewCRm8">
Итак, я пытаюсь установить ma633fFpKHYewCRm8
как String
в imageId
.
ОБНОВЛЕНИЕ 2
Возможно, одним из способов является использование FS.File Reference?