Enonic version: 6.14.0
OS: Centos 6
Hi.
I’m using libs.portal.getMultipartStream(‘file’) to upload image, but it fails when trying uploading image about 2 MB. I got “Failed to load resource: the server responded with a status of 413 (Request Entity Too Large)” .
How can I increase allowed file size?
Below is the code of this upload service:
/**
- Upload image to the folder Images of the site.
*/
var libs = {
portal: require(’/lib/xp/portal’),
content: require(’/lib/xp/content’)
};
exports.post = function(req) {
var imageMetadata = libs.portal.getMultipartItem(‘file’);
var imageFile = libs.portal.getMultipartStream(‘file’);
var createResult = libs.content.createMedia({
name: imageMetadata.fileName,
parentPath: '/' + app.config.sitename + '/images',
mimeType: imageMetadata.contentType,
branch: 'draft',
data: imageFile
});
var publishResult = libs.content.publish({
keys: [createResult._id],
sourceBranch: 'draft',
targetBranch: 'master',
includeChildren: true,
includeDependencies: false
});
var message = null;
if (publishResult) {
var imageUrl = libs.portal.imageUrl({path: createResult._path, scale: 'width(556)'});
message = imageUrl;
}
return {
body: {
result: message
},
contentType: 'application/json; charset=utf-8'
};
};
Thanks.