CORS error tryouts.
This commit is contained in:
@@ -58,10 +58,10 @@
|
||||
function uploadFile(file) {
|
||||
$("#status").html('Starting Upload...')
|
||||
url = c;
|
||||
fetch(url, {
|
||||
fetch(url, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
"content-type": "image/png"
|
||||
"content-type": "image/*"
|
||||
},
|
||||
mode: 'cors',
|
||||
body: file
|
||||
@@ -75,5 +75,6 @@
|
||||
.catch(error => $("#status").html(error)
|
||||
)
|
||||
.then(response => $("#status").html('File uploaded successfully: ' + filename + 'Response:' + response.text()));
|
||||
|
||||
}
|
||||
</script>
|
||||
14
index.js
14
index.js
@@ -23,6 +23,8 @@ const {
|
||||
|
||||
const app = express();
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.use(forceSSL());
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({ extended: true }));
|
||||
@@ -36,8 +38,6 @@ app.use("/", routes);
|
||||
|
||||
app.use("/assets", express.static("./app/public"));
|
||||
|
||||
app.use(cors());
|
||||
|
||||
app.listen(APP_PORT, () =>
|
||||
console.log(`Example app listening on port ${APP_PORT}!`)
|
||||
);
|
||||
@@ -77,7 +77,8 @@ app.get("/generateSignedURL", (req, res) => {
|
||||
//Tried to define Google ID and private key while debugging
|
||||
version: "v2", //tried v4 also
|
||||
action: "write",
|
||||
contentType: "image/*", //tried without and with specific image/png ex.
|
||||
"Content-Type": "image/*",
|
||||
//contentType: "image/*", //tried without and with specific image/png ex.
|
||||
expires: Date.now() + 86400000
|
||||
};
|
||||
const filename = req.query.filename;
|
||||
@@ -88,7 +89,12 @@ app.get("/generateSignedURL", (req, res) => {
|
||||
const [url] = await bucket.file(filename).getSignedUrl(options);
|
||||
|
||||
console.log(`The signed url is ${url}.`);
|
||||
res.send(url);
|
||||
|
||||
res.header("Access-Control-Allow-Origin", "http://localhost:5000");
|
||||
res.header("Access-Control-Allow-Methods", "PUT,OPTIONS");
|
||||
res.header("Access-Control-Allow-Headers", "Content-Type, Origin");
|
||||
res.header("Access-Control-Max-Age", "86400000");
|
||||
res.status(200).send(url);
|
||||
}
|
||||
generateSignedUrl().catch(console.error);
|
||||
});
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
[
|
||||
{
|
||||
"origin": ["http://localhost"],
|
||||
"responseHeader": ["Content-Type"],
|
||||
"method": ["GET", "HEAD", "DELETE"],
|
||||
"origin": ["*"],
|
||||
"responseHeader": [
|
||||
"Content-Type",
|
||||
"Access-Control-Allow-Origin",
|
||||
"x-goog-resumable"
|
||||
],
|
||||
"method": ["GET", "HEAD", "DELETE", "POST", "PUT", "OPTIONS"],
|
||||
"maxAgeSeconds": 3600
|
||||
}
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user