summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/files/ajax/upload.php51
-rw-r--r--apps/files/js/file-upload.js2
-rw-r--r--lib/private/connector/sabre/exception/entitytoolarge.php22
-rw-r--r--lib/private/connector/sabre/exception/unsupportedmediatype.php22
-rw-r--r--lib/private/connector/sabre/file.php16
-rw-r--r--lib/public/files/entitytoolargeexception.php11
-rw-r--r--lib/public/files/invalidcontentexception.php11
-rw-r--r--lib/public/files/invalidpathexception.php11
8 files changed, 121 insertions, 25 deletions
diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php
index 0920bf62109..45fb17de94a 100644
--- a/apps/files/ajax/upload.php
+++ b/apps/files/ajax/upload.php
@@ -110,30 +110,35 @@ if (strpos($dir, '..') === false) {
|| (isset($_POST['resolution']) && $_POST['resolution']==='replace')
) {
// upload and overwrite file
- if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
-
- // updated max file size after upload
- $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
-
- $meta = \OC\Files\Filesystem::getFileInfo($target);
- if ($meta === false) {
- $error = $l->t('Upload failed. Could not get file info.');
+ try
+ {
+ if (is_uploaded_file($files['tmp_name'][$i]) and \OC\Files\Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) {
+
+ // updated max file size after upload
+ $storageStats = \OCA\Files\Helper::buildFileStorageStatistics($dir);
+
+ $meta = \OC\Files\Filesystem::getFileInfo($target);
+ if ($meta === false) {
+ $error = $l->t('Upload failed. Could not get file info.');
+ } else {
+ $result[] = array('status' => 'success',
+ 'mime' => $meta['mimetype'],
+ 'mtime' => $meta['mtime'],
+ 'size' => $meta['size'],
+ 'id' => $meta['fileid'],
+ 'name' => basename($target),
+ 'originalname' => $files['tmp_name'][$i],
+ 'uploadMaxFilesize' => $maxUploadFileSize,
+ 'maxHumanFilesize' => $maxHumanFileSize,
+ 'permissions' => $meta['permissions'],
+ );
+ }
+
} else {
- $result[] = array('status' => 'success',
- 'mime' => $meta['mimetype'],
- 'mtime' => $meta['mtime'],
- 'size' => $meta['size'],
- 'id' => $meta['fileid'],
- 'name' => basename($target),
- 'originalname' => $files['tmp_name'][$i],
- 'uploadMaxFilesize' => $maxUploadFileSize,
- 'maxHumanFilesize' => $maxHumanFileSize,
- 'permissions' => $meta['permissions'],
- );
+ $error = $l->t('Upload failed. Could not find uploaded file');
}
-
- } else {
- $error = $l->t('Upload failed. Could not find uploaded file');
+ } catch(Exception $ex) {
+ $error = $ex->getMessage();
}
} else {
@@ -164,5 +169,5 @@ if ($error === false) {
OCP\JSON::encodedPrint($result);
exit();
} else {
- OCP\JSON::error(array('data' => array_merge(array('message' => $error), $storageStats)));
+ OCP\JSON::error(array(array('data' => array_merge(array('message' => $error), $storageStats))));
}
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index fbb53b3530a..c03e9037cec 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -345,7 +345,7 @@ $(document).ready(function() {
} else if (result[0].status !== 'success') {
//delete data.jqXHR;
data.textStatus = 'servererror';
- data.errorThrown = result.data.message; // error message has been translated on server
+ data.errorThrown = result[0].data.message; // error message has been translated on server
var fu = $(this).data('blueimp-fileupload') || $(this).data('fileupload');
fu._trigger('fail', e, data);
}
diff --git a/lib/private/connector/sabre/exception/entitytoolarge.php b/lib/private/connector/sabre/exception/entitytoolarge.php
new file mode 100644
index 00000000000..2bda51f2f3e
--- /dev/null
+++ b/lib/private/connector/sabre/exception/entitytoolarge.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Entity Too Large
+ *
+ * This exception is thrown whenever a user tries to upload a file which exceeds hard limitations
+ *
+ */
+class OC_Connector_Sabre_Exception_EntityTooLarge extends Sabre_DAV_Exception {
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 413;
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/exception/unsupportedmediatype.php b/lib/private/connector/sabre/exception/unsupportedmediatype.php
new file mode 100644
index 00000000000..95d6a8cc651
--- /dev/null
+++ b/lib/private/connector/sabre/exception/unsupportedmediatype.php
@@ -0,0 +1,22 @@
+<?php
+
+/**
+ * Unsupported Media Type
+ *
+ * This exception is thrown whenever a user tries to upload a file which holds content which is not allowed
+ *
+ */
+class OC_Connector_Sabre_Exception_UnsupportedMediaType extends Sabre_DAV_Exception {
+
+ /**
+ * Returns the HTTP status code for this exception
+ *
+ * @return int
+ */
+ public function getHTTPCode() {
+
+ return 415;
+
+ }
+
+}
diff --git a/lib/private/connector/sabre/file.php b/lib/private/connector/sabre/file.php
index 037dba7f37b..667f7407f75 100644
--- a/lib/private/connector/sabre/file.php
+++ b/lib/private/connector/sabre/file.php
@@ -98,7 +98,21 @@ class OC_Connector_Sabre_File extends OC_Connector_Sabre_Node implements Sabre_D
throw new Sabre_DAV_Exception();
}
} catch (\OCP\Files\NotPermittedException $e) {
- throw new Sabre_DAV_Exception_Forbidden();
+ // a more general case - due to whatever reason the content could not be written
+ throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
+
+ } catch (\OCP\Files\EntityTooLargeException $e) {
+ // the file is too big to be stored
+ throw new OC_Connector_Sabre_Exception_EntityTooLarge($e->getMessage());
+
+ } catch (\OCP\Files\InvalidContentException $e) {
+ // the file content is not permitted
+ throw new OC_Connector_Sabre_Exception_UnsupportedMediaType($e->getMessage());
+
+ } catch (\OCP\Files\InvalidPathException $e) {
+ // the path for the file was not valid
+ // TODO: find proper http status code for this case
+ throw new Sabre_DAV_Exception_Forbidden($e->getMessage());
}
// rename to correct path
diff --git a/lib/public/files/entitytoolargeexception.php b/lib/public/files/entitytoolargeexception.php
new file mode 100644
index 00000000000..3dff41bca02
--- /dev/null
+++ b/lib/public/files/entitytoolargeexception.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files;
+
+class EntityTooLargeException extends \Exception {}
diff --git a/lib/public/files/invalidcontentexception.php b/lib/public/files/invalidcontentexception.php
new file mode 100644
index 00000000000..184ec4d06d6
--- /dev/null
+++ b/lib/public/files/invalidcontentexception.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files;
+
+class InvalidContentException extends \Exception {}
diff --git a/lib/public/files/invalidpathexception.php b/lib/public/files/invalidpathexception.php
new file mode 100644
index 00000000000..36090ae5b48
--- /dev/null
+++ b/lib/public/files/invalidpathexception.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * Copyright (c) 2013 Thomas Müller <thomas.mueller@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OCP\Files;
+
+class InvalidPathException extends \Exception {}