Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webservice File upload with cross domain #144

Closed
SADHASIVAM-BE opened this issue Feb 22, 2014 · 5 comments
Closed

Webservice File upload with cross domain #144

SADHASIVAM-BE opened this issue Feb 22, 2014 · 5 comments

Comments

@SADHASIVAM-BE
Copy link

I tried with File Upload API in spring 3.0.5 webservice.
I get error like "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. ".
But, all other webservice call(CORS) executing perfectly..

Give solution for this issue.
High priority.

@danialfarid
Copy link
Owner

What browser, version of angular, angular-file-upload are you having this problem with?

You gotta post your js and html code here if you need help, or create a jsfiddle.

I know people are using CORS with this plugin so it is probably a request header issue or something like that.

These might help you:
#4
#113

@SADHASIVAM-BE
Copy link
Author

find my env. detail in below.. kindly give solution..

Browser : Firefox 27.0.1

Server : Spring restful service.Ver 3.0.5 ( no authentication)

HTML Code

Javascript Code

scheduler.controller('matrixController', function($scope, $http, $timeout, $upload) {
$scope.uploadRightAway = true;
$scope.onFileSelect = function($files) {
$scope.selectedFiles = [];
$scope.progress = [];
if ($scope.upload && $scope.upload.length > 0) {
for (var i = 0; i < $scope.upload.length; i++) {
if ($scope.upload[i] != null) {
$scope.upload[i].abort();
}
}
}
$scope.upload = [];
$scope.uploadResult = [];
$scope.selectedFiles = $files;
$scope.dataUrls = [];
for ( var i = 0; i < $files.length; i++) {
var $file = $files[i];
if (window.FileReader && $file.type.indexOf('image') > -1) {
var fileReader = new FileReader();
fileReader.readAsDataURL($files[i]);
function setPreview(fileReader, index) {
fileReader.onload = function(e) {
$timeout(function() {
$scope.dataUrls[index] = e.target.result;
});
};
}
setPreview(fileReader, i);
}
$scope.progress[i] = -1;
if ($scope.uploadRightAway) {
$scope.start(i);
}
}
};

$scope.start = function(index) {
    $scope.progress[index] = 0;

    $scope.upload[index] = $upload.upload({
        url : URL+'upload2',
        method: 'POST',
        headers: {},
        data : {
            myModel : 'modal',name:'MYfile'
        },
        file: $scope.selectedFiles[index],
        fileFormDataName: 'myFile'
    }).then(function(response) {
        $scope.uploadResult.push(response.data);
    }, null, function(evt) {
        $scope.progress[index] = parseInt(100.0 * evt.loaded / evt.total);
    });
};

});

Server filter (java) added like

response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
response.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept, x-requested-with, sid, mycustom, smuser");
response.addHeader("Access-Control-Max-Age", "1800");//30 min

domain like

http://localhost:8080/SchedulerUI/#matrix

Webservice like

http://localhost:8084/Scheduler/upload2

@danialfarid
Copy link
Owner

Can you copy here the request content/headers from your browser debugger tool for a regular service call versus file upload request? I want to see the difference between the request headers and content between the one that is working and the one that is not working.

Also did you try to upload using a simple html form?

<form method="post" action="http://localhost:8084/Scheduler/upload2" name="submit" enctype="multipart/form-data">
  <input type="file" name="myfile">
  <input type="submit" value="Submit">
</form>

@SADHASIVAM-BE
Copy link
Author

Yes. it's working.
Have issue in my spring code..

Sorry danial, i disturb you.. i fixed my issue.. Thanks.

@gkimpson
Copy link

gkimpson commented Feb 8, 2018

@SADHASIVAM-BE how did you fix the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants