Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support query string parameters in URLs #6

Open
scottsd opened this issue Jul 22, 2014 · 6 comments · May be fixed by #23
Open

Support query string parameters in URLs #6

scottsd opened this issue Jul 22, 2014 · 6 comments · May be fixed by #23
Labels

Comments

@scottsd
Copy link

scottsd commented Jul 22, 2014

When trying to opening an URL such as

http://www.sammobile.com/wp-content/uploads/2013/02/pixel-density-xperias.jpg?v=1

it gives

Error: Unsupported file type: .jpeg?v=140

Please support query string parameters. Some CDNs upload images in the same location, but with a new parameter to show the updated version.

@scottsd
Copy link
Author

scottsd commented Jul 22, 2014

Solution:

  var ext = path.extname(url.split("?")[0])

@scottsd
Copy link
Author

scottsd commented Aug 6, 2014

@mikolalysenko What do you think?

@mikolalysenko
Copy link
Member

I think this is a good idea, if you implement it in a PR I will merge.

@joernroeder
Copy link

Hi,
I've got another strange request error and noticed that i'm using query params as well

TypeError: Object #<IncomingMessage> has no method 'getHeader'
    at Request._callback (./node_modules/get-pixels/node-pixels.js:157:31)

@Barryrowe
Copy link
Contributor

@joernroeder I just submitted a PR that fixes some of the issues with HTTP support. It looks like the Http.IncomingMessage API doesn't support .getHeader any longer, but instead exposes .headers. I also found that if you don't explicitly set encoding:null on the request options, the body doesn't come back encoded as the parsing libraries expect.

59naga added a commit to 59naga/get-pixels that referenced this issue Apr 27, 2015
@59naga
Copy link
Contributor

59naga commented Apr 27, 2015

Hi guys. I too ran into similar problem:

getPixels('animated.gif?1430103876000',function(error,pixels){
  console.log(pixels.shape.length===3)// true
});

As Mr.scottsd stated, Backward match is not work.
Refer to my pull request.

e.g.

$ node
var path= require('path')
function getPixels(url, type, cb) {
  if(!cb) {
    cb = type
    type = ''
  }
  var ext = path.extname(url.toString().split('?')[0]) // Fixed
  switch(type || ext.toUpperCase()) {
    case '.GIF':
      // httpGif(url, cb)
      return 'gif'
    break
    default:
      if(Buffer.isBuffer(url)) {
        url = 'data:' + type + ';base64,' + url.toString('base64')
      }
      if(url.indexOf('data:image/gif;') === 0) {
        // dataGif(url, cb)
        return 'gif'
      } else {
        // defaultImage(url, cb)
        return 'default'
      }
  }
}

getPixels('http://www.sammobile.com/wp-content/uploads/2013/02/pixel-density-xperias.jpg?v=1')
// 'default'
getPixels('animated.gif')
// 'gif'
getPixels('animated.gif?1430103876000')
// 'gif'
getPixels('data:image/gif;')
// 'gif'
getPixels(new Buffer(''))
// 'default'

@59naga 59naga linked a pull request Jul 14, 2017 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants