少し信じられないJavaは、クライアント側でこれを簡単にします。サーバーファイルに画像を投稿して最初にサニタイズする必要があると確信していましたが、そのようなサーバーファイルに誰もアクセスしないようにしたい (そして少し考えます) と、写真でスパムになってしまいます. エンドユーザーによる改ざんの可能性がない厳密なプロセスが必要です。
私がそれを正しく理解していれば、私が読んだことから、PUTはまさに私が必要としているものであるはずです. 私の署名付きの ja は、サイトに関連する情報画像をクライアントからサーバーに送信しますが、私の FTP 情報を公開したり、攻撃される可能性のあるアップロード ファイルを公開したりすることはありません。PUT を正しく理解しているかどうかは、私の質問だと思います。追加の処理プロセスなしで、http 経由でアカウントに画像を配置できますか?
ちなみに、このスニペットを画像に使用するにはどうすればよいですか?
URLConnection urlconnection=null;
try{
File file = new File("C:/test.txt");
URL url = new URL("http://192.168.5.27/Test/test.txt");
urlconnection = url.openConnection();
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
if (urlconnection instanceof HttpURLConnection) {
try {
((HttpURLConnection)urlconnection).setRequestMethod("PUT");
((HttpURLConnection)urlconnection).setRequestProperty("Content-type", "text/html");
((HttpURLConnection)urlconnection).connect();
} catch (ProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
BufferedOutputStream bos = new BufferedOutputStream(urlconnection
.getOutputStream());
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(
file));
int i;
// read byte by byte until end of stream
while ((i = bis.read()) >0) {
bos.write(i);
}
System.out.println(((HttpURLConnection)urlconnection).getResponseMessage());
}
catch(Exception e)
{
e.printStackTrace();
}
try {
InputStream inputStream;
int responseCode=((HttpURLConnection)urlconnection).getResponseCode();
if ((responseCode>= 200) &&(responseCode<=202) ) {
inputStream = ((HttpURLConnection)urlconnection).getInputStream();
int j;
while ((j = inputStream.read()) >0) {
System.out.println(j);
}
} else {
inputStream = ((HttpURLConnection)urlconnection).getErrorStream();
}
((HttpURLConnection)urlconnection).disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}