pythoncorbaomniorb

How to write program to do file transfer based on based omniORBpy


I'm now writing a Corba project to do file transfering between client and server. But I face trouble when I want to upload file from the client to the server.

The IDL I defined is:

interface SecretMessage
{
    string send_file(in string file_name, in string file_obj);
};

And I implemented the uploading function in the client code:

f = open('SB.docx', 'rb')
data = ''
for piece in read_in_chunks(f):
    data += piece

result = mo.send_file('2.docx', data)

If the file is a plain txt file, there is no problem. But if the file is a, like jpg, doc, or others except txt, then it does work. It gives me the error:

omniORB.CORBA.BAD_PARAM: CORBA.BAD_PARAM(omniORB.BAD_PARAM_WrongPythonType, CORBA.COMPLETED_NO)

Where is the problem?


Solution

  • I think it is because by default omniORB wants to see ASCII data for strings. Try changing your IDL to this

    interface SecretMessage
    {
        typedef sequence<octet> OctetSequence;
        string send_file(in string file_name, in OctetSequence file_obj);
    };
    

    You can keep your Python client code the same because in the IDL to Python mapping, octet sequences map to Python strings.