Hello,
When using the MATLAB Web Server File Exchange, you may encounter an issue where the upload page seems to be stuck in a long, unending loop. This problem typically arises due to the way the File Exchange handles larger files. While it performs well with smaller files, such as those under 100 KB, larger files can cause delays. Let's explore why this happens and how you can address it:
1. The “JavaTcpServer” function processes incoming data in chunks. For larger files, this results in more iterations of the loop, thereby increasing the time required to read the entire file. Currently, the buffer used for reading data is fixed at a size of 1 MB, as shown in the code snippet below:
data = zeros(1, 1000000, 'int8'); %Increase buffer size
This buffer size may limit the amount of data read in each iteration, but the loop will continue until all data is received. To handle larger files more efficiently, I recommend increasing the buffer size based on the file size.
2. In the “upload.m” file, there is a line of code that converts images to grayscale, which adds additional processing overhead. If this conversion is not necessary for your application, consider commenting out this line to reduce processing time. Here’s a snippet illustrating how you can do this:
function html=uploadshow(headers,config)
filename_in=headers.Content.imagefile.Filename;
filename_in_html=filename_in(length(config.www_folder)+2:end)
%....rest all comment to avoid converting gray image overhead
%Change “filename_out_html” with “filename_in_html” in ‘img src’ as shown below:
html=[html '<img src="../' filename_in_html '" alt="Uploaded image"/> <br>'];
I hope this helps.