SpringBoot cannot upload large files after using Nignx - java

SpringBoot uses the Nginx reverse proxy and then opens the HTTPS protocol. If the file transfer exceeds 500KB, the data in the Request will not be received.

You need to edit your nginx.conf and add this line into the server block:
server {
client_max_body_size 10M;
}
It means setting file size upload to 10M.

Related

Spring Integration is not detecting files on FTP Folder

Currently I'm facing a problem where I don't know what to do to resolve it. I'm developing a simple application that transfer files through different FTP and SFTP servers to be processed. Well, at the beginnig those servers weren't ready, so I used Apache Mina and RebexTinySftpServer to set a FTP server and a SFTP server on my computer to test my development.
With those applications I completed and tested my application locally, so it was time to test it using the servers that will be used in production, but something is wrong with the FTP server and Spring Integration is not detecting the files that are put in the folder to be transferred to the SFTP server.
I have two folders on each server: one for Input files and the another one for Output files. So when Spring Integration detects that there's a new file in the Input folder on the SFTP Server, it transfers the file to the Input folder on FTP Server to be processed for another service. That part works fine.
After that service processes the file, it generates an output file and stores it in the Output folder on the FTP Server to be transferred to the Output folder on the SFTP server, but for some reason Spring Integration is not detecting those files and doesn't transfer none of them. This part is what I don't know how to solve because none Exception is being thrown, so I don't know what part of my code I have to modify.
Here is my code where I define the DefaultFtpSessionFactory:
public DefaultFtpSessionFactory ftpSessionFactory() {
DefaultFtpSessionFactory session = new DefaultFtpSessionFactory();
session.setUsername(username);
session.setPassword(password);
session.setPort(port);
session.setHost(host);
session.setFileType(FTP.ASCII_FILE_TYPE);
session.setClientMode(FTPClient.PASSIVE_LOCAL_DATA_CONNECTION_MODE);
return session;
}
And here is the code where I define the FTP Inbound Adapter:
#Bean
FtpInboundChannelAdapterSpec salidaAS400InboundAdapter() {
return Ftp.inboundAdapter(as400Session.ftpSessionFactory())
.preserveTimestamp(true)
.remoteDirectory(as400Session.getPathSalida())
.deleteRemoteFiles(true)
.localDirectory(new File("tmp/as400/salida"))
.temporaryFileSuffix(".tmp");
}
I should mention that the FTP Server is running on an AS/400 system, so maybe that has something to do with the situation I'm facing.
I found the solution of my problem. I'm posting this in case something similar happens to someone else.
My project is using spring-integration-ftp 5.5.16 that has commons-net 3.8.0 as a dependency. For some reason, that version of commons-net wasn't retrieving the files inside the directory of the AS400, so I excluded that dependency from spring-integration-ftp and added commons-net 3.9.0 in my project. Now everything works fine.

OneDrive download session maximum time

I am writing a program which calls OneDrive REST api to download some files (total 12G) using java on the uri:
GET /drives/{drive-id}/items/{item-id}/content
And the inputstream is closed (socket reset from server) before the end of file transfer, causing the file download failed.
I tried to put the same request in chrome and firefox, same problem also appears.
Now I know that I cloud use partial download by adding the range header to the http request(and it works like a charm):
Range: bytes=0-1023
But still, I wonder what is the maximum download time/size that will trigger the close of the connection?

Apache server repeatedly spinning if I try to retrieve files or check if folder exists

I am creating a micro service where my application will go to Apache Server to get files and folder-contents.
Not all the time, but very frequently, my Apache Server just spins when I try to see if file/folder exists:
return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
or when I try to open connection:
c = (HttpURLConnection)url.openConnection();
And I end up restarting service.
I can clearly access it by entering URL manually and get a 200 response code.
I configured Apache to allow Index view for these files and folders.
Sometimes, when I type full path to a file using IP address, it spins also.... I find this very strange.
I don't know why this would happen... Any ideas?
Version: 2.4.23 win64 VC14

change exchange content in camel

I am trying to implement a scenario using camel which is as follows:-
Get File From JMS queue.
Store the file and crc value of the file in a directory
Move the file and crc file to the SFTP server and once it is successfull
delete the files from the directory.
My route is as follows
from("jms:queue")
.to(save the file)
.process(since I have the content of the file in exchange so generating crc)
.to(file system save the crc file)
.to(Push both the files to the sftp server);
But the file that is getting uploaded to the sftp server is only crc file as it was present in the exchange.
How should I solve this Situation?
If anyone of you have come across to this problem Please Guide me.
Thanks
I think you should use a wire tap to copy your exchange to a different route and have that new route save the file and sftp it to the correct location.
from("jms:queue")
.wireTap("direct:save-file")
.process(since I have the content of the file in exchange so generating crc)
.to(file system save the crc file)
.to(Push file to the sftp server);
from("direct:save-file")
.to(save the file)
.to(Push file to the sftp server);

Remote file retrieval

In my web application (spring REST ) I have an API to upload the file to the server.I have another API which retrieve the file url to the client.
file = new File(fileName);
URL url = file.toURI().toURL();
InetAddress ip = InetAddress.getLocalHost();
String urls="file://"+ip+url.toString();
As a result I am getting file://192.168.3.37/D:/Anoop/pic/2unvvhlacq5fh09tokr7i25cvj.jpg as the url.
This works fine locally , When the application is hosted in a server url shows file not found.
Please advice.
Okay, Assuming that your server IP is 192.168.3.37 and your upload API will put the uploaded file into D:\Anoop\pic\ on the server. So what you have todo is to expose D:\Anoop\pic\ via protocols like HTTP or FTP.
Than you will have something like http://192.168.3.37/pics mapped to D:\Anoop\pic. This way, all file inside the directory were exposed using HTTP. You can do the same strategy with FTP.
So, what you return to the client is giving the URL to any speciffic file that was uploaded before, if you have uploaded the file 2unvvhlacq5fh09tokr7i25cvj.jpg and the server API put it on D:\Anoop\pic\2unvvhlacq5fh09tokr7i25cvj.jpg then it will be accessible with http://192.168.3.37/pics/2unvvhlacq5fh09tokr7i25cvj.jpg
I hope you get the idea.

Categories

Resources