-
Notifications
You must be signed in to change notification settings - Fork 30
Open
Description
client.js
Template.itemSubmit.events({
'input #pictureUpload': async function (event, template) {
// get the inputted file
const file = event.target.files[0];
// get new reader instance
const reader = new FileReader();
// fileInfo object is required as the 'file' type is not supported in methods
const fileInfo = {
size: file.size,
type: file.type.split('/')[1],
};
reader.onload = function () {
// as the reader digests the file, turn the result into a uint8array for transmission
const buffer = new Uint8Array(reader.result);
// upload the file to the server
callWithPromise('texts.uploadPictureFile', fileInfo, buffer).then(
pictureFileName => {
submitNewPictureTextItem(template, pictureFileName);
}
);
};
reader.readAsArrayBuffer(file);
},
});
methods.js
export const uploadPictureFile = new ValidatedMethod({
name: 'texts.uploadPictureFile',
validate: null,
run(fileInfo, fileData) {
console.log(fileInfo); // { size: 397470, type: 'jpeg' }
console.log(fileData); // undefined
},
});
Tried passing binary, array buffer, base64, uint8array. fileData is always undefined. When using standard Meteor method definition – this works as expected. Outputs object and array.
Metadata
Metadata
Assignees
Labels
No labels