Necesito usar esto en mi programa de rieles para que pueda obtener el contenido de la imagen y luego base64. Sé cómo basarme en él, pero no sé cómo obtendré la imagen. Alguien sabe como?Ruby file_get_contents equivalent
9
A
Respuesta
16
Editado recuperar de URL externa:
PHP:
$image = file_get_contents("http://www.example.com/file.png");
Ruby:
require 'net/http'
image = Net::HTTP.get_response(URI.parse("http://www.example.com/file.png")).body
+0
Impresionante, eres increíble. Muchas gracias VERDADERAMENTE. – deuces
1
para HTTP/HTTPS/FTP se puede utilizar el módulo OpenURI:
require "open-uri"
image = open("http://www.example.com/file.png").read
Cuestiones relacionadas
- 1. Pygame equivalent for Ruby?
- 2. metric_fu equivalent for ruby 1.9.x
- 3. Ruby String # scan equivalent to return MatchData
- 4. Autotest equivalent for PHP?
- 5. file_get_contents() Error
- 6. file_get_contents cuelga
- 7. /sharedtypes equivalent for svcutil.exe?
- 8. threading.local equivalent for twisted.web?
- 9. find_by_sql equivalent for mongoid?
- 10. python - strtotime equivalent?
- 11. unique_ptr boost equivalent?
- 12. Mono.Cecil tipo.IsAssignableFrom (derivedType) equivalent
- 13. OpenGLES 2.0: gl_VertexID equivalent?
- 14. join equivalent en Windows
- 15. Curl equivalent en nodejs?
- 16. PathCanonicalize equivalent en C#
- 17. AF_UNIX equivalent for Windows
- 18. WPF equivalent of margin-top?
- 19. C sizeof equivalent for macros
- 20. PHP Array to String equivalent
- 21. XmlAttribute/XmlElement equivalent for JavaScriptSerializer
- 22. Scikit-learn equivalent for C++?
- 23. IsNullOrEmpty equivalent for Array? C#
- 24. Parse_url equivalent in grails/groovy?
- 25. Amazon SimpleDB Identity Seed equivalent
- 26. Python getattr equivalent for dictionaries?
- 27. php file_get_contents y &
- 28. file_get_contents() para URLs cortas
- 29. file_get_contents recibir cookies
- 30. ¿File_get_contents fallará correctamente?
Quiero decir desde un sitio web. – deuces
Después de obtener el contenido del sitio, puede intentar analizarlo con la expresión regular. También puedes echar un vistazo a [nokogiri] (http://rubygems.org/gems/nokogiri) gem – ck3g