Closed crapthings closed 8 years ago
fc.insert()
creates an initial empty placeholder (zero length) file. All zero length files have the same md5 sum = d41d8cd98f00b204e9800998ecf8427e
. This is the correct behavior. The md5 value is automatically recalculated and updated after you have finished uploading data to the file.
If you want to see a working example, I suggest the sample app: https://github.com/vsivsi/meteor-file-sample-app
i can get corrent md5 after change meteor template.$.events to
myFiles.resumable.assignBrowse($(".fileBrowse"));
now it's working
but why i can't bind event myself ?
.js
myFiles = new FileCollection('myFiles', {
resumable: true,
http: [
{
method: 'get',
path: '/:md5',
lookup: function (params, query) {
console.log(params, query)
return {
md5: params.md5
};
}
}, {
method: 'put',
path: '/:md5',
lookup: function (params, query) {
return {
md5: params.md5
};
}
}, {
method: 'options',
path: '/:md5',
lookup: function (params, query) {
return {
md5: params.md5
};
},
handler: function (req, res, next) {
console.log(req, res)
res.writeHead(200, {
'Content-Type': 'text/plain',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, PUT'
});
res.end();
return;
}
}
]
});
if (Meteor.isClient) {
Meteor.startup(function () {
myFiles.resumable.assignBrowse($("#filepicker"))
myFiles.resumable.on('fileAdded', function (file) {
myFiles.insert({
_id: file.uniqueIdentifier,
filename: file.fileName,
contentType: file.file.type
},
function (err, _id) {
if (err) {
return console.error("File creation failed!", err);
}
myFiles.resumable.upload();
}
);
});
})
}
if (Meteor.isServer) {
myFiles.allow({
insert: function () {
return true
},
write: function () {
return true
},
remove: function () {
return true
},
read: function () {
return true
}
})
}
.html
<head>
<title>cordovatest</title>
</head>
<body>
{{> filepicker}}
</body>
<template name="filepicker">
<input id="filepicker" type="file">
</template>
If you want to use resumable,js to upload, then you don't need to define a PUT route because the server-side configures its own POST route. In any case, you cannot use md5
as the selector for an upload route because all empty files have the same md5 sum (as I noted above). If you are using Cordova and need to use CORS, then you do need to define an OPTIONS route for the resumable.js endpoint at /_resumable/:id
for POST requests. See: https://github.com/vsivsi/meteor-file-collection/issues/90
code