Forum: Ruby File copy from Client to Server via web-services

C5481d35bd0a7d6b135ed65cdd143fa0?d=identicon&s=25 Rails Crazy Idiot (rails_idiot)
on 2011-07-20 11:59
Hi,

I am trying to use Apache Thrift for creating an API offering many
functionalities which include file uploads as well. Nothing to bother
about, it is another full-stack language independent client/server
webserice like SOAP.

It supports, int, string, bool and some other basic stuff. There is no
File datatype in the Thrift service, which I can use to send the files
attaching them directly. The max I should be using for file uploads is
the string datatype.

I have received some advice from some Thrift guys saying that we can
definitely upload some files through the thrift web services. I have to
convert the file into binary strings, assign that converted string to a
string variable and then send it via thrift to the server.

In this process, I am able to convert the file into a string by the
File.read('<file_path>','rb'){|f| f.read}  OR
IO.read('<file_path>')
command.

I am able to send them across the Thrift service, but I have to convert
it on the server side to the actual file.

When I am doing the writing with the help of File.new

File.new('<new_file_path>','w'){|f| f << transferred_file_content}

, I am actually not getting the complete file. The size of the file is
almost equal to the actual file(infact a little more), but the file is
not complete. This is working for simple txt files, but if I want to use
this for .doc and PDF files, this is not working. I think there is
something I am missing.

Really appreciate some help on this.

Sandy
E088bb5c80fd3c4fd02c2020cdacbaf0?d=identicon&s=25 "Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> (Guest)
on 2011-07-20 13:42
(Received via mailing list)
On Wed, Jul 20, 2011 at 11:59 AM, Rails Crazy Idiot
<mail2sanand@gmail.com> wrote:
> the string datatype.
>
> this for .doc and PDF files, this is not working. I think there is
> something I am missing.

Try writing it as binary:

File.new('<new_file_path>','wb'){|f| f << transferred_file_content}

(note the 'wb' flag passed to File.new)

Jesus.
C5481d35bd0a7d6b135ed65cdd143fa0?d=identicon&s=25 Rails Crazy Idiot (rails_idiot)
on 2011-07-20 18:20
Hats Off to you Jesus. Thanks for the help. I got it. Will revert if any
other issues

Sandy

"Jesús Gabriel y Galán" <jgabrielygalan@gmail.com> wrote in post
#1011860:
> On Wed, Jul 20, 2011 at 11:59 AM, Rails Crazy Idiot
> <mail2sanand@gmail.com> wrote:
>> the string datatype.
>>
>> this for .doc and PDF files, this is not working. I think there is
>> something I am missing.
>
> Try writing it as binary:
>
> File.new('<new_file_path>','wb'){|f| f << transferred_file_content}
>
> (note the 'wb' flag passed to File.new)
>
> Jesus.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.