So I have used this function from gstore gem
def add_file_to_bucket( bucket, name, file )
@client.put_object( bucket, name, :data => File.read( file ) )
end
I was playing around in irb and noticed the output of File.read is a
string so I thought I could make this function
def add_string_to_bucket( bucket, name, string )
@client.put_object( bucket, name, :data => string )
end
when I run it I don’t get any errors but when I check my google storage
with gsutil there is no new file either
I don’t see a difference and was wondering if any one had any insights
as to why this wont work. Thank you
On Thu, Jul 14, 2011 at 12:46:46PM +0900, Tyrel R. wrote:
So I have used this function from gstore gem
def add_file_to_bucket( bucket, name, file )
@client.put_object( bucket, name, :data => File.read( file ) )
end
This is very un-idiomatic Ruby, and you might want to consider at least
altering your indentation style. Using your style:
def foo
# do stuff
end
. . . leaves hanging indents and clashes with idiomatic Ruby style. The
way basically everybody else does it gives visual cues to the end of a
given scope or semi-atomic chunk of code by pairing the def and the end
at the same level of indentation:
def foo
# do stuff
end
Thank you for your response I do write like that already but I should be
more careful when I am posting.
I still am very curious though:
If the output of File.read( ‘/path/to/file/file.extension’ )
Is a string
And I have this function
def add_file_to_bucket( bucket, name, file )
@client.put_object( bucket, name, :data => File.read( file ) )
end
Which works if I pass a name of a file on my hard drive for the
last parameter file like
add_file_to_bucket( 'some_bucket', 'some_custom_name', 'some_file' )
Why it is that if I define this function
def add_string_to_bucket( bucket, name, string )
@client.put_object( bucket, name, :data => string )
end
And call it like
string = some_data_feed.convert_to_string
add_string_to_bucket( 'some_bucket', 'some_custom_name', string )
It will run through the function without errors but it will not
actually upload any files to the bucket.
Never mind my last post I think it was that the name I chose for the
object in the bucket had a space in it but if I follow google’s naming
convintions everything works just fine. Thank you everyone.