Here is the full code of JS and background Java:
function Uploadimage ()
{
UUID = new uuid (). Createuuid ();
var fileName = $ ("#videoImage"). Val ();
var array1=filename.split (".");
if (array1[array1.length-1]== "jpg" | | array1[array1.length-1]== "JPG")
{
$.ajaxfileupload ({
URL: ' Upload!uploadimage.action ',
Secureuri:false,
files:[$ (' #videoImage ')],
DataType: ' JSON ',
Global:false,
data:{"videoImageFileName1": uuid+ "." +ARRAY1[1], "UUID": uuid},
Complete:function ()
{
Alert ("Upload success");
$ ("#image"). attr ("src", "tem/" +username+ "/" +uuid+ "." +array1[1]+ ". jpg?" +math.random ());
$ ("#xttp"). attr ("src", "tem/" +username+ "/" +uuid+ "." +array1[1]+ ". jpg?" +math.random ());
$ ("#picName"). Val (FileName);
$ ("#lla"). HTML (fileName);
$ ("#videoImage"). ReplaceWith (' <input type= "file" Name= "Videoimage" style= "width:455px" id= "Videoimage" Onchange= "Uploadimage ()" class= "Uplod"/> ");
}
});
}else
{
Alert (' Please select JPG image ');
}
}
FTP upload
Private Boolean ftpupload (string IP, String userName, string password,
File srcfile, String directory) {
Boolean res = false;
FtpClient ftpclient = new FtpClient ();//FTP Client
try {
int indexOf = Directory.indexof ("/");
String user = directory.substring (0, indexOf);//Get Upload Path
String md5str = directory.substring (indexOf + 1);
Ftpclient.connect (IP);//Create a connection based on IP
Boolean r0 = Ftpclient.login (userName, password);//FTP Login
Boolean r1 = ftpclient.makedirectory ("/img/" + user);//ftp Create folder
Boolean r2 = ftpclient.makedirectory ("/img/" + user + "/" + md5str);//ftp Create encrypted folder
Boolean r3 = Ftpclient.changeworkingdirectory ("/img/" + user+ "/" + md5str);//ftp Change Working directory
SYSTEM.OUT.PRINTLN ("FTP img:" +directory+ "" +r0+ "" +r1+ "" +r2+ "" +r3 ");
Ftpclient.setbuffersize (1024);//Set Stream size
Ftpclient.setsotimeout (3600000);//Set delay
Ftpclient.setdefaulttimeout (3600000);//Set Default timeout time
Ftpclient.setfiletype (Ftpclient.binary_file_type);//Set File type
String rname = "Img.jpg";
FileInputStream FileInputStream = new FileInputStream (srcfile);//Get text input stream
res = Ftpclient.storefile (New String (Rname.getbytes ("UTF-8"), "iso-8859-1"), fileinputstream);//Upload file
Fileinputstream.close ();//file input stream off
Ftpclient.logout ();//Return login
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (ftpclient.isconnected ()) {//Close client
try {
Ftpclient.disconnect ();//close connection
} catch (IOException e) {
E.printstacktrace ();
}
}
}
return res;
}
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java JS file images are uploaded and synced via FTP