GithubHelp home page GithubHelp logo

Comments (18)

Cherepanov6 avatar Cherepanov6 commented on May 29, 2024 131

Add the "Access-Control-Expose-Headers" header to response from server. To read from javaScript "content-disposition" header add to response on server this Access-Control-Expose-Headers:Content-Disposition. Then this code will work: response.headers.get('content-disposition')

from isomorphic-fetch.

malagant avatar malagant commented on May 29, 2024 24

At least I don't believe that this is an issue of isomorpic-fetch oder fetch either.
We use a rails api backend and solved the issue with this in a cors initializer:

# Be sure to restart your server when you modify this file.

# Avoid CORS issues when API is called from the frontend app.
# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests.

# Read more: https://github.com/cyu/rack-cors

if Rails.env == 'development'
    Rails.application.config.middleware.insert_before 0, Rack::Cors do
      allow do
        origins 'localhost:10020'

        resource '*',
          headers: :any,
          methods: [:get, :post, :put, :patch, :delete, :options, :head],
          expose: [
            'X-Total', 
            'X-Total-Pages', 
            'X-Page', 
            'X-Per-Page', 
            'X-Next-Page', 
            'X-Prev-Page',
            'X-Offset',
            'X-Rdb-Lang'
          ]
      end
    end
end

As you can see, we are exposing explicitly needed headers. And so should you with content-disposition.
Although this is a rails example. You should be able to expose the headers in JavaScript also.

Hope this helps someone.

from isomorphic-fetch.

wdamianw avatar wdamianw commented on May 29, 2024 18

In C# you could do so by writing:
result.Content.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
At least it worked for me finally.

from isomorphic-fetch.

jch254 avatar jch254 commented on May 29, 2024 16

@malagant you're right! Even if the headers show in Chrome devtools they're not necessarily included in a CORS response. I explicitly exposed the Content-Disposition header server side and all worked. Cheers cheers!

from isomorphic-fetch.

av1v3k avatar av1v3k commented on May 29, 2024 6

I did set the response header mentioned by @Cherepanov6 in Express NodeJS with the below code.

res.setHeader('Access-Control-Expose-Headers','Content-Disposition');

Thanks @Cherepanov6 !

from isomorphic-fetch.

derekgray23 avatar derekgray23 commented on May 29, 2024 4

I have same issue, can see 'X-Total-Count' in Chrome devtool, but there is no such key in fetch's response headers.

from isomorphic-fetch.

sharan5am avatar sharan5am commented on May 29, 2024 4

If you are using django, you would add this to settings file:
CORS_EXPOSE_HEADERS =[
'content-disposition',
]

from isomorphic-fetch.

tw-360vier avatar tw-360vier commented on May 29, 2024 2

Since this is an issue with the browser side implementation (https://github.com/github/fetch) of this package, doesn't this issue belong there?
Also, i think my problems are probably caused by some missing CORS settings:
JakeChampion/fetch#399

from isomorphic-fetch.

huync94 avatar huync94 commented on May 29, 2024 1

Add the "Access-Control-Expose-Headers" header to response from server. To read from javaScript "content-disposition" header add to response on server this Access-Control-Expose-Headers:Content-Disposition. Then this code will work: response.headers.get('content-disposition')

thank you, You saved my day.

from isomorphic-fetch.

cmloegcmluin avatar cmloegcmluin commented on May 29, 2024

We are experiencing a similar issue. The response object coming back from fetch is missing headers besides content-type. In our case we are looking for X-Vcap-Request-Id.

we're able to see a number of headers in the network tab of chrome's devtools, but the only one that is available via the headers through this lib is response.headers.get('content-type')

from isomorphic-fetch.

malagant avatar malagant commented on May 29, 2024

Any news on this? I have the very same problem and I am getting nervous. ;)

from isomorphic-fetch.

tw-360vier avatar tw-360vier commented on May 29, 2024

I'm having a similar problem: the only headers i can see are: 'cache-control', 'content-type' and 'expires'.
I can see more headers in chrome devtools, too. And i really need to read those hawk headers...

from isomorphic-fetch.

jch254 avatar jch254 commented on May 29, 2024

Me too. Seeing the Content-Disposition header in Chrome devtools but response.headers.get('content-disposition') is null :s

from isomorphic-fetch.

george-norris-salesforce avatar george-norris-salesforce commented on May 29, 2024

Using isomorphic-fetch in Node/Express to request images from third party API (thus can't control certain CORs settings). Is there a way to get a full set of headers from Fetch/third party API? Using Node Request exposes all headers, Fetch does not.

Only headers returned in Fetch are:
cache-control
expires
content-type
content-length

from isomorphic-fetch.

JoshMcCullough avatar JoshMcCullough commented on May 29, 2024

No resolution to this yet?! :(

from isomorphic-fetch.

dhkha2749 avatar dhkha2749 commented on May 29, 2024

In C# you could do so by writing:
result.Content.Headers.Add("Access-Control-Expose-Headers", "Content-Disposition");
At least it worked for me finally.

Step 1: first just check Content-Disposition in header response
step 2 : .WithExposedHeaders("Content-Disposition") as this in cors access or startup.cs class in a case of Asp.net core
Step 3 : ( blob).name = this.getResponseHeader('content-disposition').match(/filename=(.+);/)[1].replace(/(^")|("$)/g, '');

from isomorphic-fetch.

kul-swat avatar kul-swat commented on May 29, 2024

(file gets saved in binary format in the browser. the filename is in the client's Network/header/Content-Disposition, we need to fetch the filename)

In Server-side code:
node js code-
response.setHeader('Access-Control-Expose-Headers','Content-Disposition');
response.download(outputpath,fileName);

In client-side code:
1)appComponent.ts file
import { HttpHeaders } from '@angular/common/http';
this.reportscomponentservice.getReportsDownload(this.myArr).subscribe((event: any) => {
var contentDispositionData= event.headers.get('content-disposition');
let filename = contentDispositionData.split(";")[1].split("=")[1].split('"')[1].trim()
saveAs(event.body, filename);
});
2) service.ts file
import { HttpClient, HttpResponse } from '@angular/common/http';
getReportsDownload(myArr): Observable<HttpResponse> {
console.log('Service Page', myArr);
return this.http.post(PowerSimEndPoints.GET_DOWNLOAD_DATA.PROD, myArr, {
observe: 'response',
responseType: 'blob'
});
}

from isomorphic-fetch.

f-starace avatar f-starace commented on May 29, 2024

Does anybody know how to expose "Content-Disposition" header in Next-js. I tried editing the next.config.js file according to this article but with no luck.

/** @type {import('next').NextConfig} */
module.exports = {
  reactStrictMode: true,
  typescript: {
    ignoreBuildErrors: true,
  },
  async headers() {
    const securityHeaders = [
      {
        key: 'X-Content-Type-Options',
        value: 'nosniff'
      },
      // here
      { key: "Access-Control-Expose-Headers", value: "Content-Disposition" },
    ]
    return [
      {
        source: '/:path*', // req path
        headers: securityHeaders
      }
    ]
  }
}

from isomorphic-fetch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.