@@ -149,38 +149,24 @@ public class ImageFoundRequestHandler implements RequestHandler {
|
||||
YandexSearchResponse.ImageResult image = allUniqueImages.getFirst();
|
||||
String url = image.getUrl();
|
||||
Path tempFile = null;
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
|
||||
|
||||
log.info(String.valueOf(image));
|
||||
log.info(String.valueOf(image));
|
||||
log.info(String.valueOf(image));
|
||||
log.info(String.valueOf(image));
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
|
||||
log.info(image.getPageTitle());
|
||||
log.info(image.getPageUrl());
|
||||
log.info(image.getHost());
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info(url);
|
||||
log.info(url);
|
||||
log.info(url);
|
||||
log.info(url);
|
||||
log.info(url);
|
||||
log.info(url);
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
log.info("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
try {
|
||||
tempFile = fileUploadService.downloadImageFromUrl(url);
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
log.info("tempFile: " + tempFile.toAbsolutePath());
|
||||
|
||||
String filePath = tempFile.toAbsolutePath().toString();
|
||||
|
||||
|
||||
@@ -614,15 +614,38 @@ public class FileUploadServiceImpl implements FileUploadService {
|
||||
Path tempFile = Files.createTempFile("upload_check_", extension);
|
||||
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
|
||||
connection.setConnectTimeout(5000);
|
||||
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36");
|
||||
connection.setConnectTimeout(10000);
|
||||
connection.setReadTimeout(10000);
|
||||
connection.setInstanceFollowRedirects(true);
|
||||
|
||||
try {
|
||||
int responseCode = connection.getResponseCode();
|
||||
System.out.println("Response code: " + responseCode);
|
||||
|
||||
if (responseCode != 200) {
|
||||
throw new IOException("Bad response code: " + responseCode);
|
||||
}
|
||||
|
||||
try (InputStream in = connection.getInputStream()) {
|
||||
Files.copy(in, tempFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
|
||||
long size = Files.size(tempFile);
|
||||
System.out.println("File downloaded: " + tempFile + ", size: " + size + " bytes");
|
||||
|
||||
if (size == 0) {
|
||||
throw new IOException("Downloaded empty file");
|
||||
}
|
||||
|
||||
return tempFile;
|
||||
|
||||
} catch (Exception e) {
|
||||
Files.deleteIfExists(tempFile);
|
||||
throw new IOException("Failed to download: " + urlString, e);
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private UploadProgressResponse handleExistingChunk(FileUploadSession session,
|
||||
|
||||
Reference in New Issue
Block a user