So have set up file uploading with gridFS both for the files I want people to share and the pictures. The problem is however, that if the file is bigger than 2mb it shaves it off and gives me a non-working file.
Here is my collections.js , where I define the FS.Collection .
// Model files
Modelfiles = new FS.Collection('modelfiles', {
stores: [new FS.Store.FileSystem('modelfiles')]
});
And here is my upload template:
<template name="upload">
<div class="container">
<div class="uploadform">
<h2>Upload your model</h2>
{{#if currentUser}}
<form class="new-model">
<div class="uploadTitle">
<label for="title">Title: </label>
<input type="text" name="title" placeholder="Fill in the model title">
</div>
<div class="uploadFile">
<label for="modelfiles">Choose files: </label>
<input type="file" name="modelfiles" id="modelfile" multiple="">
</div>
<div class="uploadDescription">
<label for="description">Description: </label>
<textarea name="description" style="" placeholder="Please enter a description"></textarea>
</div>
<div class="uploadCategory">
<label for="category">Choose category</label>
<select name="category">
<option>Art</option>
<option>Architecture</option>
<option>Characters</option>
<option>Fashion</option>
<option>Gadgets</option>
<option>Hobby</option>
<option>Jewelery</option>
<option>Tools</option>
<option>Toys</option>
</select>
</div>
<div class="uploadImages">
<div class="imageUploadInfo"><span>Optimal image ratio is 4:3.</span><div class="arrowDown"></div></div>
<label for="images">Choose images(optional): <i class="fa fa-info imageInfo"></i></label>
<input type="file" name="images" id="modelimage" class="myFileInput" multiple="">
</div>
<div class="isPremium">
<label for="price">Price: </label><br/>
<span class="amount">Amount: </span><input class="priceModelInput" type="text" name="price" id="priceModelInput" placeholder="Please enter the price">
<input type="checkbox" name="freeModel" value="Free"> Free
</div>
<div class="uploadCategory">
<label for="license">Choose License</label>
<select class="licenseSelectBox" name="license">
<option value="0">Choose a license</option>
<option value="1">Creative Commons - Zero</option>
<option value="2">Creative Commons BY-NC 4.0</option>
<option value="3">Creative Commons SA-BY</option>
<option value="4">Commercial license</option>
</select>
<br>
<br>
</div>
<input type="submit" value="Upload">
</form>
{{else}}
{{redirectUser}}
{{/if}}
</div>
</div>
</template>
And lastly, where I handle the file upload in the upload.js file.
Template.upload.events({
'submit .new-model': function(event, template) {
var title = event.target.title.value;
var description = event.target.description.value;
var category = event.target.category.value;
var images = event.target.images.files;
var files = event.target.modelfiles.files;
var freemodel = event.target.freeModel.checked;
var license = event.target.license.value;
//console.log(freemodel);
if(!freemodel) {
var price = event.target.price.value;
} else {
var price = 0;
}
var userid = Meteor.userId();
console.log("We are trying to process the upload");
Models.insert({
title: title,
description: description,
category: category,
price: price,
createdAt: new Date(),
license: license,
user: userid
}, function(err, id) {
if(err) {
console.log(err);
FlashMessages.sendError(err);
Router.go('upload');
} else {
modelid = id;
console.log(modelid);
for(var i = 0, ln = images.length; i < ln;i++) {
var pic = new FS.File(images[i]);
if(images[0]) {
var mainImage = true;
} else {
var mainImage = false;
}
pic.metadata = {
modelid: modelid,
main: mainImage
}
Modelpictures.insert(pic, function(err, fileObj) {
if(err) {
console.log(err);
FlashMessages.sendError(err);
Router.go('upload');
} else {
console.log("Imageupload successful");
console.log(modelid);
console.log(fileObj);
}
});
}
for(var i = 0, ln = files.length; i < ln;i++) {
var file = new FS.File(files[i]);
file.metadata = {
modelid: modelid
}
// Get file type
var _name = file.name();
var _posOfType = _name.indexOf(".");
//console.log("Position of filetype " + _posOfType);
if(_posOfType) {
var _type = _name.substr(_posOfType);
} else {
var _type = "unknown";
}
file.type(_type);
console.log("The file type is " + file.type());
console.log("The file " + file.name());
// GridFS
Modelfiles.insert(file, function(err, fileObj) {
if(err) {
console.log(err);
FlashMessages.sendError(err);
Router.go('upload');
} else {
console.log("Fileupload successful");
console.log(modelid);
console.log(fileObj);
}
});
}
}
});
//Change role
Meteor.call('userRoleDesigner');
console.log("I am supposed to redirect you now!");
Router.go('home');
return false;
}
});
Does anyone any suggestion on this ?
Here I havent defined the max file size and I have tried to define it as bigger than 2mb. But it does not help.
Here is the console log I get:
We are trying to process the upload
upload.js:157 I am supposed to redirect you now!
upload.js:40 Ji6u9WJWrvmMctyDi
upload.js:99 The file type is .stl
upload.js:101 The file BeardedYell_Low_137k_Solid.stl
upload.js:125 Fileupload successful
upload.js:126 Ji6u9WJWrvmMctyDi
upload.js:127 FS.File {createdByTransform: true, original: Object, data: DataMan, metadata: Object, collectionName: "modelfiles"…}
cfs_base-package.js:108 Access denied [403]defaultCallback @ cfs_base-package.js:108(anonymous function) @ cfs_file.js:287args.(anonymous function) @ matb33_collection-hooks.js:399wrappedCallback @ collection.js:544(anonymous function) @ dynamics_browser.js:51_.extend._maybeInvokeCallback @ livedata_connection.js:391_.extend.receiveResult @ livedata_connection.js:411_.extend._livedata_result @ livedata_connection.js:1516onMessage @ livedata_connection.js:256(anonymous function) @ stream_client_sockjs.js:172_.each._.forEach @ underscore.js:105self.socket.onmessage @ stream_client_sockjs.js:171REventTarget.dispatchEvent @ sockjs-0.3.4.js:87SockJS._dispatchMessage @ sockjs-0.3.4.js:1072SockJS._didMessage @ sockjs-0.3.4.js:1130that.ws.onmessage @ sockjs-0.3.4.js:1277
4cfs_upload-http.js:109 The provided value 'undefined' is not a valid enum value of type XMLHttpRequestResponseType.
And here is the image: