views:

75

answers:

2

hi all, here is what i want to do and need some help in it.

I have a source url and a destination url. what i want to do is copy a file from a source url to the destination url, but I want to avoid copying the file locally on my system before uploading the file again.

Also what is must to have is that we should get the content-length because the destination api requires it (its custom). If I use the HttpUrlConnection class then i can get that....but AFAIK there are some issues in using java.net for anything other than GET. (the source files are huge image/video files), so i can using apache httpclient 3.1. But how do i approach this?

any thoughts?

-Ash

+1  A: 

Did you try the following?

See this tutorial.

EDIT

You should be able to get the response size of the GET with GetMethod.getResponseContentLenght (which corresponds to the Content-Length header, if provided).

Then I suggest you look at one of the following for the PUT method: setRequestContentLenght, addContentLenghtRequestHeader, setContentChunked.

ewernli
yes, but how do i get the content-length from InputStream is = getMethod.getResponseBodyAsStream(); ?I do not want to download the file locally...Any ideas?-Ash
ashchawla
A: 

I want to avoid copying the file locally on my system before uploading the file again

Well you're going to have to live with it, because that's how HTTP works. If you want to do remote-to-remote transfers, you're going to either use something other than HTTP (although I don't know of any protocol suitable for that), or remotely execute some software on one of the remote sites to perform the transfer.

skaffman