Skip to content

Apache Lucene open-source search software

SOLR-7782 Allow non-JSON and JSON array uploads

Upayavirad821ea9fd2fe
diff --git a/solr/webapp/web/js/angular/controllers/documents.js b/solr/webapp/web/js/angular/controllers/documents.js
index 30fc5534ce1..bf0e350aa02 100644
--- a/solr/webapp/web/js/angular/controllers/documents.js
+++ b/solr/webapp/web/js/angular/controllers/documents.js
@@ -85,35 +85,43 @@ solrAdminApp.controller('DocumentsController',
if ($scope.type == "json" || $scope.type == "wizard") {
postData = "[" + $scope.document + "]";
- contentType = "application/json";
+ contentType = "json";
} else if ($scope.type == "csv") {
postData = $scope.document;
- contentType = "application/csv";
+ contentType = "csv";
} else if ($scope.type == "xml") {
postData = "<add>" + $scope.document + "</add>";
- contentType = "text/xml";
+ contentType = "xml";
} else if ($scope.type == "upload") {
doingFileUpload = true;
params.raw = $scope.literalParams;
} else if ($scope.type == "solr") {
postData = $scope.document;
if (postData[0] == "<") {
- contentType = "text/xml";
- } else if (postData[0] == "{") {
- contentType = "application/json";
+ contentType = "xml";
+ } else if (postData[0] == "{" || postData[0] == '[') {
+ contentType = "json";
} else {
alert("Cannot identify content type")
}
}
if (!doingFileUpload) {
- Update.post(params, postData).then(function (success) {
- $scope.responseStatus = "success";
- delete success.$promise;
- delete success.$resolved;
- $scope.response = JSON.stringify(success, null, ' ');
- }).fail(function (failure) {
+ var callback = function (success) {
+ $scope.responseStatus = "success";
+ delete success.$promise;
+ delete success.$resolved;
+ $scope.response = JSON.stringify(success, null, ' ');
+ };
+ var failure = function (failure) {
$scope.responseStatus = failure;
- });
+ };
+ if (contentType == "json") {
+ Update.postJson(params, postData, callack, failure);
+ } else if (contentType == "xml") {
+ Update.postXml(params, postData, callback, failure);
+ } else if (contentType == "csv") {
+ Update.postCsv(params, postData, callback, failure);
+ }
} else {
var file = $scope.fileUpload;
console.log('file is ' + JSON.stringify(file));
diff --git a/solr/webapp/web/js/angular/services.js b/solr/webapp/web/js/angular/services.js
index 63c393653ae..0147d172d68 100644
--- a/solr/webapp/web/js/angular/services.js
+++ b/solr/webapp/web/js/angular/services.js
@@ -78,10 +78,13 @@ solrAdminServices.factory('System',
}])
.factory('Update',
['$resource', function($resource) {
- return $resource('/solr/:core/:handler', {core: '@core', wt:'json', _:Date.now(), handler:'/update'}, {
+ return $resource('/solr/:core/:handler', {core: '@core', wt:'json', _:Date.now(), handler:'update'}, {
"optimize": {params: { optimize: "true"}},
"commit": {params: {commit: "true"}},
- "post": {method: "POST", params: {handler: '@handler'}}
+ "post": {headers: {'Content-type': 'application/json'}, method: "POST", params: {handler: '@handler'}},
+ "postJson": {headers: {'Content-type': 'application/json'}, method: "POST", params: {handler: '@handler'}},
+ "postXml": {headers: {'Content-type': 'text/xml'}, method: "POST", params: {handler: '@handler'}},
+ "postCsv": {headers: {'Content-type': 'application/csv'}, method: "POST", params: {handler: '@handler'}}
});
}])
.service('FileUpload', function ($http) {