Request header field X-Parse-Application-ID is not allowed by Access-Control-Allow-Headers in preflight response.
Hello such community I have the following question'm trying to upload a file, but I have the following error
add these lines of code for testing file uploading #20 change the application ID and the rest-api-key and finally add a service to upload the file
Upload: function(file) {
var defer = $q.defer();
var parseFile = new Parse.File(file.name, file);
parseFile.save({
success: function(savedFile) {
defer.resolve(savedFile);
},
error: function(error) {
defer.reject(error);
}
});
return defer.promise;
but it continues to appear the same mistake :(
MLHttpRequest cannot load https://xxxxxxxx/parse/files/4188biun0z82kklf3euc_400x400.jpeg. Request header field X-Parse-Application-ID is not allowed by Access-Control-Allow-Headers in preflight response. main.js:43 Unable to connect to the Parse API
Anyone know how I solve this?
Thank you very much for your time
Have you set the correct serverURL including parse mount point in your app? If so, then this sounds like a CORS issue that we should fix. In the meantime, the workaround would be to host your parse server and your website on the same domain (including subdomain). This is definitely not the ideal situation, though, so we will definitely seek to address this bug. You could also submit a PR :)
hello @drew-gross replace the app-id and the rest-api-key
app.all('', function(req, res, next) { res.header('Access-Control-Allow-Origin', ''); res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS'); res.header('Access-Control-Allow-Headers', 'accept, content-type,aa, bb, x-parse-session-token'); // intercept OPTIONS method if ('OPTIONS' == req.method) { res.send(200); } else { next(); } });
aa = x-parse-application-id bb = x-parse-rest-api-key
I make a small application to test that everything is working . the parse.initializate is this
Parse.initialize('cc','dd'); Parse.serverURL = 'https://urlheroku.com/parse';
cc = application_id dd = javacript_key
all right even create a new document in mongodb no problem. this detail when uploading a file.
I will be doing wrong? thanks for you time.
We'll do some additional investigation. In the meantime, if you could provide a complete reproduction script or test case that would be very helpful (ie. a parse-server application and JS application that we can run and instantly see the problem)
I'm having this issue just trying to connect through the JS SDK: ERR Connection refused: {code: 100, message: "XMLHttpRequest failed: "Unable to connect to the Parse API""}
+1
got same error...
"XMLHttpRequest cannot load http://localhost:1337/parse/classes/Generic. Request header field X-Parse-Application-Id is not allowed by Access-Control-Allow-Headers in preflight response."
using below simple restful call fails connecting to parse-server and same code works via parse.com (commented out line below)
any help would be really appreciated - thanks
$.ajax({ type: "GET", //url: "https://api.parse.com/1/classes/Generic", // works url: "http://localhost:1337/parse/classes/Generic", // fails data: "", contentType: "application/json", headers: { "Content-Type": "application/json", "X-Parse-Application-Id":"app key", "X-Parse-REST-API-Key":"rest api key" }, success: function(data){ console.log(data); } });
ran into same bug and can't find any solution - would really appreciate any pointers
This issue is fixed in ParsePlatform/parse-server#390 If you don't want to wait for the next release, you can clone the repo and run the master branch.