Java JS file images are uploaded and synced via FTP

Source: Internet
Author: User
Tags ftp login uuid ftp client

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.