mirror of
				https://github.com/gyurix1968/guacamole-client.git
				synced 2025-10-30 00:23:21 +00:00 
			
		
		
		
	GUAC-1172: Implement file upload through object streams.
This commit is contained in:
		| @@ -27,6 +27,7 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||||
|         function clientController($scope, $routeParams, $injector) { |         function clientController($scope, $routeParams, $injector) { | ||||||
|  |  | ||||||
|     // Required types |     // Required types | ||||||
|  |     var ManagedClient      = $injector.get('ManagedClient'); | ||||||
|     var ManagedClientState = $injector.get('ManagedClientState'); |     var ManagedClientState = $injector.get('ManagedClientState'); | ||||||
|     var ManagedFilesystem  = $injector.get('ManagedFilesystem'); |     var ManagedFilesystem  = $injector.get('ManagedFilesystem'); | ||||||
|     var ScrollState        = $injector.get('ScrollState'); |     var ScrollState        = $injector.get('ScrollState'); | ||||||
| @@ -635,6 +636,25 @@ angular.module('client').controller('clientController', ['$scope', '$routeParams | |||||||
|         ManagedFilesystem.changeDirectory(filesystem, file); |         ManagedFilesystem.changeDirectory(filesystem, file); | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Begins a file upload through the attached Guacamole client for | ||||||
|  |      * each file in the given FileList. | ||||||
|  |      * | ||||||
|  |      * @param {FileList} files | ||||||
|  |      *     The files to upload. | ||||||
|  |      */ | ||||||
|  |     $scope.uploadFiles = function uploadFiles(files) { | ||||||
|  |  | ||||||
|  |         // Ignore file uploads if no attached client | ||||||
|  |         if (!$scope.client) | ||||||
|  |             return; | ||||||
|  |  | ||||||
|  |         // Upload each file | ||||||
|  |         for (var i = 0; i < files.length; i++) | ||||||
|  |             ManagedClient.uploadFile($scope.client, files[i], $scope.filesystemMenuContents); | ||||||
|  |  | ||||||
|  |     }; | ||||||
|  |  | ||||||
|     // Clean up when view destroyed |     // Clean up when view destroyed | ||||||
|     $scope.$on('$destroy', function clientViewDestroyed() { |     $scope.$on('$destroy', function clientViewDestroyed() { | ||||||
|  |  | ||||||
|   | |||||||
| @@ -171,6 +171,7 @@ | |||||||
|             <!-- Stationary header --> |             <!-- Stationary header --> | ||||||
|             <div class="header"> |             <div class="header"> | ||||||
|                 <h2>{{filesystemMenuContents.name}}</h2> |                 <h2>{{filesystemMenuContents.name}}</h2> | ||||||
|  |                 <button class="upload button" guac-upload="uploadFiles">{{'CLIENT.ACTION_UPLOAD_FILES' | translate}}</button> | ||||||
|                 <button class="back" ng-click="hideFilesystemMenu()">Back</button> |                 <button class="back" ng-click="hideFilesystemMenu()">Back</button> | ||||||
|             </div> |             </div> | ||||||
|  |  | ||||||
|   | |||||||
| @@ -438,9 +438,31 @@ angular.module('client').factory('ManagedClient', ['$rootScope', '$injector', | |||||||
|      *  |      *  | ||||||
|      * @param {File} file |      * @param {File} file | ||||||
|      *     The file to upload. |      *     The file to upload. | ||||||
|  |      * | ||||||
|  |      * @param {ManagedFilesystem} [filesystem] | ||||||
|  |      *     The filesystem to upload the file to, if any. If not specified, the | ||||||
|  |      *     file will be sent as a generic Guacamole file stream. | ||||||
|  |      * | ||||||
|  |      * @param {ManagedFilesystem.File} [directory=filesystem.currentDirectory] | ||||||
|  |      *     The directory within the given filesystem to upload the file to. If | ||||||
|  |      *     not specified, but a filesystem is given, the current directory of | ||||||
|  |      *     that filesystem will be used. | ||||||
|      */ |      */ | ||||||
|     ManagedClient.uploadFile = function uploadFile(managedClient, file) { |     ManagedClient.uploadFile = function uploadFile(managedClient, file, filesystem, directory) { | ||||||
|         managedClient.uploads.push(ManagedFileUpload.getInstance(managedClient.client, file)); |  | ||||||
|  |         // Use generic Guacamole file streams by default | ||||||
|  |         var object = null; | ||||||
|  |         var streamName = null; | ||||||
|  |  | ||||||
|  |         // If a filesystem is given, determine the destination object and stream | ||||||
|  |         if (filesystem) { | ||||||
|  |             object = filesystem.object; | ||||||
|  |             streamName = (directory || filesystem.currentDirectory).streamName + '/' + file.name; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Start and manage file upload | ||||||
|  |         managedClient.uploads.push(ManagedFileUpload.getInstance(managedClient.client, file, object, streamName)); | ||||||
|  |  | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
|     return ManagedClient; |     return ManagedClient; | ||||||
|   | |||||||
| @@ -124,11 +124,19 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector' | |||||||
|      * @param {File} file |      * @param {File} file | ||||||
|      *     The file to upload. |      *     The file to upload. | ||||||
|      *      |      *      | ||||||
|  |      * @param {Object} [object] | ||||||
|  |      *     The object to upload the file to, if any, such as a filesystem | ||||||
|  |      *     object. | ||||||
|  |      * | ||||||
|  |      * @param {String} [streamName] | ||||||
|  |      *     The name of the stream to upload the file to. If an object is given, | ||||||
|  |      *     this must be specified. | ||||||
|  |      * | ||||||
|      * @return {ManagedFileUpload} |      * @return {ManagedFileUpload} | ||||||
|      *     A new ManagedFileUpload object which can be used to track the |      *     A new ManagedFileUpload object which can be used to track the | ||||||
|      *     progress of the upload. |      *     progress of the upload. | ||||||
|      */ |      */ | ||||||
|     ManagedFileUpload.getInstance = function getInstance(client, file) { |     ManagedFileUpload.getInstance = function getInstance(client, file, object, streamName) { | ||||||
|  |  | ||||||
|         var managedFileUpload = new ManagedFileUpload(); |         var managedFileUpload = new ManagedFileUpload(); | ||||||
|  |  | ||||||
| @@ -137,7 +145,14 @@ angular.module('client').factory('ManagedFileUpload', ['$rootScope', '$injector' | |||||||
|         reader.onloadend = function fileContentsLoaded() { |         reader.onloadend = function fileContentsLoaded() { | ||||||
|  |  | ||||||
|             // Open file for writing |             // Open file for writing | ||||||
|             var stream = client.createFileStream(file.type, file.name); |             var stream; | ||||||
|  |             if (!object) | ||||||
|  |                 stream = client.createFileStream(file.type, file.name); | ||||||
|  |  | ||||||
|  |             // If object/streamName specified, upload to that instead of a file | ||||||
|  |             // stream | ||||||
|  |             else | ||||||
|  |                 stream = object.createOutputStream(file.type, streamName); | ||||||
|  |  | ||||||
|             var valid = true; |             var valid = true; | ||||||
|             var bytes = new Uint8Array(reader.result); |             var bytes = new Uint8Array(reader.result); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user