Giter Club home page Giter Club logo

Comments (5)

alexander-fenster avatar alexander-fenster commented on May 24, 2024

Hi @dragoncodes, thank you for the report! Would it be possible for you to take my changes from #158, apply it to the code in your node_modules/gaxios and check if it helped to solve your original problem with the publisher API?

The code in build/src/gaxios.js (after TypeScript compilation) should be like this:

@@ -137,7 +152,9 @@
             }
             else if (typeof opts.data === 'object') {
                 opts.body = JSON.stringify(opts.data);
-                opts.headers['Content-Type'] = 'application/json';
+                if (!Object.keys(opts.headers).some((key) => key.match(/^content-type$/i))) {
+                    opts.headers['Content-Type'] = 'application/json';
+                }
             }
             else {
                 opts.body = opts.data;

If you confirm it fixes the problem for you, we'll release the updated version. If not, we'll keep debugging :)

Thank you!

from gaxios.

dragoncodes avatar dragoncodes commented on May 24, 2024

I tried to test the fix for the apk upload (Content-Type: application/vnd.android.package-archive), but another request can't go through because it's in application/x-www-form-urlencoded, but the data is still being stringified.

This leads me to believe that a lot of users, including other libraries, have been relying on this behavior and changes may become "breaking".

To test out the full procedure in my case I added a reversed flag disableAutomaticHeaderResolution:

   if (this.isReadableStream(opts.data)
                || this.opts.disableAutomaticHeaderResolution) { // <- this bit
                opts.body = opts.data;
            } else if (typeof opts.data === 'object') { ... }

It seems like a dirty fix, but it can then be adopted faster and safer.

from gaxios.

alexander-fenster avatar alexander-fenster commented on May 24, 2024

Thanks @dragoncodes, I'm reverting my fix for now (#161). We'll figure out what to do here :)

from gaxios.

CodeWithOz avatar CodeWithOz commented on May 24, 2024

Any progress with this? I want to use this lib but I'm worried about this potentially causing problems.

from gaxios.

bcoe avatar bcoe commented on May 24, 2024

@dragoncodes I'm wondering if behavior might have changed since this issue was opened...

But you should be able to set a custom content-type header as long as you're providing a string or readable stream body. (Buffer isn't actually a type accepted by the underlying node-fetch library, or at least it's not documented that it does).

So, I think you can modify your code to something like this, and it would work:

const apk = fs.readFileSync(apkFilePath);

this.publisher.edits.apks.upload({
           editId,
           packageName,
           media: {
               mimeType: 'application/vnd.android.package-archive',
               body: apk.toString()
            }
}, (err, res) => {});

or,

const apk = fs.readFile(apkFilePath);

this.publisher.edits.apks.upload({
           editId,
           packageName,
           media: {
               mimeType: 'application/vnd.android.package-archive',
               body: apk // <-- readable stream.
            }
}, (err, res) => {});

@CodeWithOz this library should work for you 👍

I'm pretty sure the problem described here was either:

  1. missing documentation , or.
  2. a bug with the upstream googleapis library, which uses gaxios.

from gaxios.

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.