Comments (5)
I had the same error so I broke down the code and stuck in a trace, similar to this:
url = URI.parse('http://www.imageshack.us/upload_api.php')
file = 'c:/x.jpg'
io = UploadIO.new(jpg, "image/jpeg", 'c:/x.jpg')
req = Net::HTTP::Post::Multipart.new url.path, io
http = Net::HTTP.new(url.host, url.port)
http.set_debug_output $stderr if true # dump out stuff
res = http.start { |http| http.request(req) }
puts res
My problem occurred because I was posting via https - http worked fine - which I resolved by adding this line to the above code, before the 'http.start' line:
require 'net/https'
http.use_ssl = url.port == 443
Hope this helps.
from multipart-post.
This helped ;)
If someone has a better solution I'm open for proposal, but here is my final implementation.
It handles redirection and save the file into a temp file that is returned (unclosed)
require 'uri' require 'net/http' require 'net/https' def http_fetch( uri_str, temp_file_name, limit = 10 ) # You should choose better exception. raise ArgumentError, 'HTTP redirect too deep' if limit == 0 url = URI.parse( uri_str ) req = Net::HTTP::Get.new url.path http = Net::HTTP.new(url.host, url.port) if url.scheme == "https" http.use_ssl = url.port == 443 end #http.set_debug_output $stderr if true # dump out stuff begin response = http.start { |http| http.request(req) } case response when Net::HTTPRedirection then http_fetch(response['location'], temp_file_name, limit - 1 ) when Net::HTTPSuccess then file = ::Tempfile.new( temp_file_name ) file.binmode file.unlink file.write( response.body ) file.rewind file else response.error! end end rescue EOFError # Reached the end of the response end
from multipart-post.
Can you please confirm if this is still an issue?
from multipart-post.
I tried all the above methods to no avail ... does anyone know what the real problem is ... looks like in this context does not have anything to do with net/http(s) because I see this error on following line:
file = 'iron_man.jpg'
io = UploadIO.new(file, 'image/jpeg')
do we know why is that happening?
from multipart-post.
What error are you seeing?
from multipart-post.
Related Issues (20)
- Deprecations aren't required HOT 3
- Force warning HOT 4
- Multipart post with a zip file HOT 2
- Issues with darkfish docs? HOT 5
- Allow UploadIO to accept additional MIME headers as options HOT 4
- 3.0 release changes HOT 8
- Timeout on JRuby on Windows HOT 11
- Tests failing on Windows HOT 1
- Changes in v2.1.0 HOT 2
- NoMethodError: undefined method `alphanumeric' for SecureRandom:Module HOT 3
- Does multipart-post follow Semantic versioning? HOT 2
- Feature request: Don't set "local.path" as a default filename to prevent it from being detected as a binary HOT 5
- CI needed HOT 1
- Can you push a new version to RubyGems? 🙏🏻 HOT 3
- Release a 2.2.0 HOT 3
- Specify correct Ruby version required in 2.2.0 HOT 8
- 2.2.2 breaks compatibility with older Rubies HOT 8
- Silence Noisy Deprecation Warnings HOT 3
- Please inlcude README / LICENSE file into the package. HOT 2
- Namespace conflict issue after 2.2.0 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from multipart-post.