Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
JavaScript and XMLHttpRequest - CORS Error Content Type Application/Octet-Stream

I am using XMLHttpRequest to make api requests. I am getting CORS error and when I inspect the browser I see that the request.send(event.target.result)is underlined in red which is where the error is coming from. I set my headers correct. Why is this happening? Works fine in localhost but when server file is pushed to heroku I get this error

***SERVER***
const express = require('express');
const bodyParser =  require('body-parser')
require('dotenv').config();
const https = require('https');
const port = process.env.PORT || 5000;
const app = express();
const cors = require('cors');

//Setting up the cors config
app.use(cors());


//Prevent application from crashing if incorrect route
app.all('*', (req, res, next) =>{
  const err = new Error(`Requested URL ${req.path} not found!`);
  err.statusCode = 404;
  next(err);
})

app.use((err, req, res, next) =>{
  const statusCode = err.statusCode || 500;
  res.status(statusCode).json({
    success: 0,
    message: err.message,
    stack: err.stack
  })
})


//Serve static files if in production
if(process.env.NODE_ENV === 'production'){

  //Set static folder
  app.use(express.static('client/build'));

  app.get('*', (req, res) =>{
    res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html'))
  });
}



app.listen(port, () => console.log(`Server started on port ${port}`));
***FRONTEND***
      let fileReader = new FileReader()
      fileReader.readAsArrayBuffer(images[0])

      let request = new XMLHttpRequest()
      request.open('POST',apiRoute,true)
      request.setRequestHeader("Content-Type", "application/octet-stream");
      request.setRequestHeader("image-data", JSON.stringify(data));

      fileReader.addEventListener('load',(event)=>{


      request.send(event.target.result)//When I inspect the browser, it underlines this line in red
      })
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!