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

319
Views
Cors Origin in Direct Path in laravel when calling images

now I build web application using laravel 5.2 as webserivce and angular2 as front page I use VR Library from http://cdn.pannellum.org My Issue When I call link Of Iamge from my database like mywebsite.com/public/Images/photo7.png return to me this message

'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:5565' is therefore not allowed access.

but I Handled this issue before I start project to transfer data from laravel and angular but when I call my images from direct Path return to me this message

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Laravel 5 (L5): In my project in, when I return image (file) and want to avoid CORS i use following code (I change it a little by hand without testing but it should work):

private function responseFile($filePath, $fileMimeType,  $originalFileName) {

    $headers = array(
        'Content-Type' => $fileMimeType,
        //'Content-Disposition' => 'attachment; filename="'. $attachment->org_name . '"', - this header is added automaticaly
        "Access-Control-Allow-Origin" => request()->getSchemeAndHttpHost() // allow CORS (e.g. for images)
    );

    return response()->download($filePath, $originalFileName, $headers);
}

In this solution you don't need to touch apache .htaccess file (or nginx config files) at all (if you do it it will cause errors with headers duplication) - because in this case we use so called Simple CORS request.

You can also read this answer to avoid other problems which can cause that CORS error.

about 4 years ago · Santiago Trujillo Report

0

Try these methods:

  1. Install and config Cors from enter link description here
  2. Add Cors mode
fetch(url,{mode:"cors"})
                    .then(res => res.blob())
                    .then(blob => {
                        const file = new File([blob], 'dot.png', {type:'image/png'});
                        console.log(file);
                    });
  1. Resource from enter link description here
about 4 years ago · Santiago Trujillo Report
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!