Open NaderIkladious opened 8 years ago
Currently dealing with the same problem, any solutions?
Buffer is Server-Only.
Also method-calls use DDP and thats much slower then HTTP which gets used if you insert on the client.
https://github.com/CollectionFS/Meteor-CollectionFS#initiate-the-upload
The insert method can directly accept a variety of different file representations as its first argument:
Hmm, on second view, you are using Uint8Array
which is labeled as "both" so you might just have to add a type somehow.. (might have to do some more digging here)
Also the Meteor.call
callback always returns (error, result)
A suggestion in https://github.com/CollectionFS/Meteor-CollectionFS/issues/367 is to use base64.
I can't seem to get this to work :(
client side
import axios from 'axios';
const url = "http://localhost:3000/methods/insertImage";
export default function upload(file: File) {
if (!file) return;
let reader = new FileReader(); //create a reader according to HTML5 File API
reader.onload = function(event){
let buffer = new Uint8Array(reader.result); // convert to binary
console.log('buffer: ', buffer);
axios.post(url, buffer);
};
}
meteor server side
Meteor.methods({
insertImage: (file) => {
const fsFile = new FS.File(file);
Images.insert(fsFile, function (err, fileObj) {
if (err) throw new Meteor.Error('500', err, err);
console.log(fileObj);
return 'success: ' + fileObj;
});
}
});
I get DataMan constructor received data that it doesn't support
Error: DataMan constructor requires a type argument when passed a Uint8Array