]> source.dussan.org Git - nextcloud-server.git/commitdiff
catch exceptions while uploading and pass on the error message
authorThomas Müller <thomas.mueller@tmit.eu>
Tue, 8 Oct 2013 13:03:24 +0000 (15:03 +0200)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 8 Oct 2013 13:03:24 +0000 (15:03 +0200)
apps/files/ajax/upload.php
apps/files/js/file-upload.js

index 0920bf62109d7adcb42bb8523a2f69b525d06caa..45fb17de94ae94875f3f94b916e04d82343d84ad 100644 (file)
@@ -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))));
 }
index b52221ac1fc1953f234a62823c5cd54cffbab055..88d5a05107f3d0e7a40d624b2b03d13c069bb35c 100644 (file)
@@ -365,7 +365,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);
                                }