Reputation: 1169
I want to send pdfs to a client webservice url using Java. How can this be done?
Upvotes: 0
Views: 337
Reputation: 68847
A few simple steps. I will add some terms between brackets for googling.
Here is some sample code.
InputStream in = new FileInputStream(file);
OuputStream os = socket.getOutputStream();
DataOutputStream dos = new DataOutputStream(os);
int n;
byte[] b = new byte[1024 * 16];
while ((n = in.read(b)) != -1)
{
dos.writeByte(1); // tell the server a buffer is coming
dos.writeInt(n); // tell it the how big the buffer is
dos.write(b, 0, n); // write the buffer
}
dos.writeByte(0); // tell the server no more buffers are coming.
dos.flush();
Now, it is up to you to write the server part of it.
Upvotes: 1