## What is the best solution to upload a image bytearray to a URL POST request in Java?

I am trying to upload the image to linkedin POST URL, to create an image based share.

## python bytearray to C++ object

I’m wondering if I could get some help. For context, I’m using some C++ libraries to generate some large (think hundreds of Mb) objects that I want to send over a network from a server to a client.

On the server, I’ve got the following:

``````PyObject*  CKKSwrapper::SerializePrivateKey() {
std::string s;
std::ostringstream os(s);
Serial::Serialize(m_keys.publicKey, os, SerType::BINARY);

auto msg = os.str();
return PyBytes_FromString(&msg(0));
}
``````

which gives me some Python object. I then send this directly to the client via python sockets. I’m reading it in like

``````def _safe_recv_abstract(socket: Socket, deserializer_func):
expected_length = _get_obj_size(socket)
running_length = 0
running_msg = bytearray()
while running_length < expected_length:
msg = socket.recv(expected_length)
if msg:
running_msg = cppwrapper.Accumulator(running_msg, bytearray(msg))
running_length += len(msg)

if optional_pycrypto_deserialize_func:
return deserializer_func(running_msg)
return running_msg
``````

two things:

1. Accumulator (from `cppwrapper.Accumulator()` above) looks like
``````PyObject* CKKSwrapper::Accumulator(PyObject a, PyObject b){
return PyByteArray_Concat(&a, &b);
}
``````
1. `deserializer_func` calls an underlying C++ function that looks like
``````void CKKSwrapper::DeserializeX(
const boost::python::list &pyvals) {

auto msg= pythonListToCppVectorBytes(pyvals);

LPPrivateKey<DCRTPoly> sk;
std::istringstream is(string(msg.begin(), msg.end()));
Serial::Deserialize(sk, is, SerType::BINARY);

this->m_keys.secretKey = sk;
}
``````

I’m running into the following error:

``````Boost.Python.ArgumentError: Python argument types in
CKKSwrapper.Accumulator(bytearray, bytearray)
did not match C++ signature:
Accumulator(pycrypto::CKKSwrapper {lvalue}, _object*, _object*)
``````

I completely understand what it is saying and that the types are wrong but I’m not sure WHY. From the docs

``````PyObject* PyByteArray_Concat(PyObject *a, PyObject *b)
Return value: New reference.

Concat **bytearrays** a and b and return a new bytearray with the result.
``````

If I understand correctly, I AM passing in bytearrays but it says that it is expecting objects?

The reason I’m trying to do it this way is that when I use a bytearray or a list for the accumulation, i.e

``````while running_length < expected_length:
msg = socket.recv(expected_length)
if msg:
running_msg = cppwrapper.Accumulator(running_msg, bytearray(msg))
running_length += len(msg)
``````

the memory usage and runtime blow up

## What would be the best way to compare two bytearray in python?

I have a ‘first bytearray’ with some hex values with, lets say 30 bytes. On the other hand ‘second bytearray’ is having 8 bytes of hex data. now if i want to search ‘second bytearray’ in first one, what would be the best way to do in python?

Aside to this, can i search the ‘second bytearray’ in specific position from first one? lets say from firstbytearr(3:10), as second bytearray is having 8 bytes of data.

``````padding_size=16
secondbytearr = bytearray.fromhex(sp)
if (firstbytearr(3:10)== secondbytearr(0:)):
print "matched"
$$``$$
``````

## Python ByteArray () combining matrix values?

``````>>> bytearray ([2,88])
bytearray (b & # 39;  x02X & # 39;)
``````

Why does Bytearray () combine them? And why is he turning 88 into ascii (X)? I expected two separate values, and 88 to convert to hex (x58)

``````bytearray (b & # 39;  x02, x58)
``````