Skip to content

Uploading binary or typed array returns undefined on server #88

@Lamer217

Description

@Lamer217

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions