-1
我已經開發了一個簡單的web服務在linux上將圖像上傳到計算機。保存文件位置有問題。當我登上形象,它成爲沒有迴應而且我已經導入所有需要包。在linux中的java開發設置路徑
@Path("/files")
public class V1_status {
/**
* Upload a File
*/
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String uploadFile(
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition fileDetail){
saveToDisk(uploadedInputStream, fileDetail);
return"File uploaded successfully!";
}
// save uploaded file to a defined location on the server
private void saveToDisk(InputStream uploadedInputStream,FormDataContentDisposition fileDetail
) {
String uploadedFileLocation= "/home/fairlady/Pictures" +fileDetail.getFileName();
try {
OutputStream out= new FileOutputStream(new File(uploadedFileLocation));
int read = 0;
byte[] bytes = new byte[1024];
out= new FileOutputStream(new File(uploadedFileLocation));
while ((read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
'它保存文件的位置有一些問題。「但你沒有告訴我們這是什麼。 –
除了任何其他評論或答案,從安全角度來看,這些代碼是非常不安全的。這幾乎是路徑遍歷攻擊的教科書定義。爲了你自己,不要在任何地方部署此代碼。 – Aurand