这就是我想做的事情,并且需要一些帮助。
我有一个源网址和一个目标网址。我想要做的是将文件从源 url 复制到目标 url,但我想避免在再次上传文件之前在系统上本地复制该文件。
另外,我们必须获得内容长度,因为目标 api 需要它(它的自定义)。如果我使用 HttpUrlConnection 类,那么我可以得到它......但是据我所知,使用 java.net 进行除 GET 之外的任何操作都存在一些问题。 (源文件是巨大的图像/视频文件),所以我可以使用apache httpclient 3.1。但我该如何处理这个问题呢?
有什么想法吗?
-灰
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
发布评论
评论(2)
您尝试过以下操作吗?
请参阅此教程。
编辑
您应该能够使用 GetMethod.getResponseContentLenght (对应于
Content-Length
标头,如果提供)。那么我建议您查看以下
PUT
方法之一: setRequestContentLenght,addContentLenghtRequestHeader , setContentChunked。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 theContent-Length
header, if provided).Then I suggest you look at one of the following for the
PUT
method: setRequestContentLenght, addContentLenghtRequestHeader, setContentChunked.,您将不得不忍受它,因为这就是 HTTP 的工作原理。如果你想进行远程到远程的传输,你要么使用 HTTP 以外的协议(尽管我不知道有什么协议适合这种情况),要么在远程站点之一上远程执行一些软件执行转移。
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.