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

Failed to upload image: 400 Bad Request #91

Open
zhaoguoyuan opened this issue Dec 15, 2014 · 10 comments
Open

Failed to upload image: 400 Bad Request #91

zhaoguoyuan opened this issue Dec 15, 2014 · 10 comments

Comments

@zhaoguoyuan
Copy link
Contributor

require 'etsy'
Etsy.silent_errors = false
Etsy.api_key='xxxx'
Etsy.api_secret='xxxx'
Etsy.protocol = 'https'
access = {:access_token => 'xxxx', :access_secret => 'xxxx'}
listing = Etsy::Listing.find(yyyy)
Etsy::Image.create(listing, 'C:/temp/test.jpg', access)

=> #<Etsy::Response:0x2e4b338 @raw_response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>>

Other calling of api all works fine.

I debugged it, the body of raw_response said "please make sure both width and height are greater than 10px", but I am quite sure that test.jpg satisfy this condition.

@zhaoguoyuan
Copy link
Contributor Author

I think I have found out the solution(bug):

fix:
secure_client.rb:
Before change:

value.read

After change:

open(value.path, "rb") {|io| io.read }

Cause:
The reason is that for reading binary file value.read won't work on windwos. For ruby > 1.9.2 we can also read binary file with IO.binread, but for compatibility this solution should be fine.

Concern:
I havn't test this on other platform yet.

@kytrinyx
Copy link
Collaborator

Thanks for figuring it out. Do you want to submit a fix, or should I go ahead and make the change?

@zhaoguoyuan
Copy link
Contributor Author

It is my pleasure to submit a fix, but please let me test it also on other platform first.

@kytrinyx
Copy link
Collaborator

Excellent. I can test it on Mac. Linux as well, though it requires a little bit more setup.

@zhaoguoyuan
Copy link
Contributor Author

Ahh, it would be very helpful if you can, thank you in advance.

@kytrinyx
Copy link
Collaborator

I tested the open(value.path, "rb") {|io| io.read } and it is going to work just fine on Mac.

@zhaoguoyuan
Copy link
Contributor Author

Can I have the permission for committing the new fixing branch?

@kytrinyx
Copy link
Collaborator

If you have a fork of the repository you can submit a pull request.

@zhaoguoyuan
Copy link
Contributor Author

Sorry, do you means fork a repository, create a bug fix branch , fix it on the new branch and pull request on that repository?

@kytrinyx
Copy link
Collaborator

Yes:

  1. Create a fork of this repository: https://github.com/kytrinyx/etsy/fork
  2. Create a bugfix branch on the new fork (which will be https://github.com/zhaoguoyuan/etsy)
  3. When you push to that branch, there will be a button to create a pull request, which will go back to this repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants