summary refs log tree commit diff
path: root/webclient
diff options
context:
space:
mode:
authorEmmanuel ROHEE <erohee@amdocs.com>2014-08-21 13:36:14 +0200
committerEmmanuel ROHEE <erohee@amdocs.com>2014-08-21 15:00:20 +0200
commit9d4bc8985f72ffffedd510eaa39b2bd5dc71f9ed (patch)
treee6a1b98df511e10e7af1e07b6725e3e91d80464c /webclient
parentAdded resizeImage() (diff)
downloadsynapse-9d4bc8985f72ffffedd510eaa39b2bd5dc71f9ed.tar.xz
Made uploadContent compatible for sending Blob objects
Diffstat (limited to 'webclient')
-rw-r--r--webclient/components/matrix/matrix-service.js26
1 files changed, 22 insertions, 4 deletions
diff --git a/webclient/components/matrix/matrix-service.js b/webclient/components/matrix/matrix-service.js
index cd37a0c234..fa5a6091d3 100644
--- a/webclient/components/matrix/matrix-service.js
+++ b/webclient/components/matrix/matrix-service.js
@@ -61,14 +61,22 @@ angular.module('matrixService', [])
         return doBaseRequest(config.homeserver, method, path, params, data, undefined);
     };
 
-    var doBaseRequest = function(baseUrl, method, path, params, data, headers) {
-        return $http({
+    var doBaseRequest = function(baseUrl, method, path, params, data, headers, $httpParams) {
+
+        var request = {
             method: method,
             url: baseUrl + path,
             params: params,
             data: data,
             headers: headers
-        });
+        };
+
+        // Add additional $http parameters
+        if ($httpParams) {
+            angular.extend(request, $httpParams);
+        }
+
+        return $http(request);
     };
 
 
@@ -326,7 +334,17 @@ angular.module('matrixService', [])
             var params = {
                 access_token: config.access_token
             };
-            return doBaseRequest(config.homeserver, "POST", path, params, file, headers);
+
+            // If the file is actually a Blob object, prevent $http from JSON-stringified it before sending
+            // (Equivalent to jQuery ajax processData = false)
+            var $httpParams;
+            if (file instanceof Blob) {
+                $httpParams = {
+                    transformRequest: angular.identity
+                };
+            }
+
+            return doBaseRequest(config.homeserver, "POST", path, params, file, headers, $httpParams);
         },
         
         // start listening on /events