Python feature suggestion - load (binary) content from file

2011-04-10 Thread Ana Nelson
I've just implemented this in a project:

binary_data = open(self.filename(), "rb").read()
mimetype, encoding = mimetypes.guess_type(self.filename())
if not mimetype:
mimetype = 'application/octet-stream' # Riak's own default
self.riak_object = self.bucket.new_binary(
self.hashstring,
binary_data,
mimetype
)


which writes binary data to a Riak bucket from a file, using Python's
mimetypes library to determine the content type from the file's extension.

I think it could be convenient to have this be included in the Riak Python
client, so perhaps it can implement better buffering. Something like
bucket.new_binary_from_file(key, filename)
___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


Re: Python feature suggestion - load (binary) content from file

2011-04-12 Thread Ana Nelson
Hi,

If Eric or someone has time to do this, that would be great. Otherwise I'll
try to put a pull request together this weekend.

-Ana


On Tue, Apr 12, 2011 at 4:10 PM, Eric Moritz wrote:

> If you don't have this integrated into the Riak Python client, I'll be
> happy to do that for you.
>
> Thanks,
> Eric Moritz.
>
> On Sun, Apr 10, 2011 at 10:49 AM, Ana Nelson  wrote:
> > I've just implemented this in a project:
> >
> > binary_data = open(self.filename(), "rb").read()
> > mimetype, encoding = mimetypes.guess_type(self.filename())
> > if not mimetype:
> >
> > mimetype = 'application/octet-stream' # Riak's own
> default
> > self.riak_object = self.bucket.new_binary(
> > self.hashstring,
> > binary_data,
> > mimetype
> >
> > )
> >
> > which writes binary data to a Riak bucket from a file, using Python's
> > mimetypes library to determine the content type from the file's
> extension.
> >
> > I think it could be convenient to have this be included in the Riak
> Python
> > client, so perhaps it can implement better buffering. Something like
> > bucket.new_binary_from_file(key, filename)
> >
> > ___
> > riak-users mailing list
> > riak-users@lists.basho.com
> > http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
> >
> >
>
___
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com