How can I send a generic file to a jersey service and receive it correctly?

末鹿安然 提交于 2019-12-05 14:19:45

You're client code is faulty.

while ((len = is.read(buf)) > 0) {
  ...
  is.read(buf);
  ...
}

You're reading from the InputStream twice in every iteration. Remove the read statement from the loop's body and you'll be fine.

You've also said that the code presented in your question works with text files. I think that doesn't work either. Reading twice from the file you're trying to upload means you're uploading only half of its contents. Half a text file is still a text file, but half a PDF is only rubbish, so you can't open the latter. You should have double checked if the contents of your uploaded and saved text file is the same as the original.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!