Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

267
Views
¿Cómo escribo datos binarios en gcs con ruby de manera eficiente?

Quiero cargar datos binarios directamente en el almacenamiento de GCP, sin escribir el archivo en el disco. A continuación se muestra el fragmento de código que he creado para llegar al estado en el que voy a estar.

 require 'google/cloud/storage' bucket_name = '-----' data = File.open('image_block.jpg', 'rb') {|file| file.read } storage = Google::Cloud::Storage.new("project_id": "maybe-i-will-tell-u") bucket = storage.bucket bucket_name, skip_lookup: true

Ahora quiero poner estos data directamente en un archivo en gcs, sin tener que escribir un archivo en el disco.

¿Hay una manera eficiente de que podamos hacer eso?

Probé el siguiente código

 to_send = StringIO.new(data).read bucket.create_file to_send, "image_inder_11111.jpg"

pero esto arroja un error que dice

 /google/cloud/storage/bucket.rb:2898:in `file?': path name contains null byte (ArgumentError) from /home/inder/.gem/gems/google-cloud-storage-1.36.1/lib/google/cloud/storage/bucket.rb:2898:in `ensure_io_or_file_exists!' from /home/inder/.gem/gems/google-cloud-storage-1.36.1/lib/google/cloud/storage/bucket.rb:1566:in `create_file' from champa.rb:14:in `<main>'
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Como sugirió @stefan, debería ser to_send = StringIO.new(data), es decir, sin .read (que devolvería una cadena nuevamente)

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!