Skip to content

Commit

Permalink
Augmentation de la taille limite des requêtes sur l'API
Browse files Browse the repository at this point in the history
Correction d'un bug lors de l'upload d'image via l'API
  • Loading branch information
Samy Laumonier committed Jun 24, 2015
1 parent ffd3f12 commit be74add
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
6 changes: 6 additions & 0 deletions lib/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Router.configureBodyParsers = function() {
Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
extended: true,
limit: '20mb'
}), {where: 'server'});
};
14 changes: 6 additions & 8 deletions private/doc/event/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* @apiHeader {String} X-User-Id User ID
*
* @apiParam {String} name Name of the event
* @apiParam {Date} begin Begin date
* @apiParam {Date} end Ending date
* @apiParam {Date} begin Begin date, format: DD/MM/YYYY HH:mm
* @apiParam {Date} end Ending date, format: DD/MM/YYYY HH:mm
* @apiParam {Double} price Price of the event
* @apiParam {String} address Address where the event takes place
* @apiParam {String} zipCode ZIP code
Expand All @@ -24,20 +24,18 @@
* @apiParam {String} link Link to a website or to a page
* @apiParam {String} comment Description of the event
* @apiParam {String} image Format: "data:[MIME_TYPE];base64,[BASE64]". You have to replace "[MIME_TYPE]" with
* the image MIME type and "[BASE64]" with the base64 encoded image file.
* the image MIME type and "[BASE64]" with the base64 encoded image file. Request
* size limit: 20mb.
*
* @apiSuccess {String} status Request result
* @apiSuccess {Object} id Event ID
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "statusCode": 200,
* "status": "success",
* "data": {
* "_id": "XbGwBxK9hc2NGeoi2",
* "name": "Event title",
* "description": "Event description"
* }
* "id": "XbGwBxK9hc2NGeoi2"
* }
*
* @apiError EventNotFound The ID of the event was not found.
Expand Down
31 changes: 24 additions & 7 deletions server/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var base64Img = Meteor.npmRequire('base64-img');
var fs = Meteor.npmRequire('fs');
var path = Meteor.npmRequire('path');

restivusInit = function() {
Restivus.configure({
Expand Down Expand Up @@ -88,18 +90,33 @@ restivusInit = function() {
}

this.bodyParams.groupId = this.user.groupId;
this.bodyParams.date = new Date();

var image = this.bodyParams.image;
delete this.bodyParams.image;
var id = Events.insert(this.bodyParams);

// Create image
base64Img.imgSync(image, UPLOAD_FULL_PATH, id, function(err) {
if (err) {
throw err;
}
});
var id = Events.insert(this.bodyParams);

if (id) {
// Create image
base64Img.imgSync(image, UPLOAD_FULL_PATH, id);
var files = fs.readdirSync(UPLOAD_FULL_PATH);
var imageExtension = null;

files.forEach(function (file) {
if (file.lastIndexOf(id, 0) === 0) {
imageExtension = path.extname(file);

return false;
}
});

Events.update(id, {
$set: {
imageExtension: imageExtension
}
});

return {
statusCode: 200,
status: 'success',
Expand Down

0 comments on commit be74add

Please sign in to comment.