Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transfer images between servers?

Tags:

php

jsp

servlets

I have a java servlet which accepts an image a user uploads to my web app.

I have another server (running php) which will host all the images. How can I get an image from my jsp server to my php server? The flow would be something like:

public class ServletImgUpload extends HttpServlet 
{   
    public void doPost(HttpServletRequest req, HttpServletResponse resp) 
      throws ServletException, IOException 
    {
        // get image user submitted
        // try sending it to my php server now
        // return success or failure message back to user
    }
}

Thanks

like image 679
user246114 Avatar asked Nov 06 '22 11:11

user246114


1 Answers

A few solutions off the top of my head...

  • Use HTTP POST to send the file. Probably not a good idea if the files are large.
  • Use FTP. This easily gives you authentication, handling of large files, etc. Bonus points for using SFTP.
  • Use a program like rsync [over ssh] to migrate the directory contents from one server to the other. Not a good solution if you have disk space concerns since you'd be storing the same files twice, once per server.

Also, remember to consider how often images are going to be pushed to your servlet. You don't want to try holding 100s of images and their transfers' network sockets in memory - save the images to the disk in this instance.

like image 123
Sam Bisbee Avatar answered Nov 11 '22 06:11

Sam Bisbee