ExtJS: File Upload instance

Source: Internet
Author: User
Tags dateformat save file

ExtJS: File Upload instance

ExtJS: File Upload instance

Var ext_dateFormat = 'Y-m-d H: I: s'; var dateFormat = 'yyyy-MM-dd HH: mm: ss'; var date = new Date (); ext. onReady (function () {var partition P = Ext. create ('ext. form. panel ', {renderTo: 'fi-form', width: 500, frame: true, title: 'file upload', bodyPadding: '10 10 0', ults: {anchor: '200', allowBlank: false, msgTarget: 'nee', labelWidth: 80}, items: [{xtype: 'textfield ', fieldLabel: 'sample number', id: 'finfo', name: 'fin Fo '}, {xtype: 'Container', layout: 'hbox', items: [{xtype: 'textfield', fieldLabel: 'Current longitude ', id: 'flongout ', name: 'background', msgTarget: 'day', allowBlank: false, labelWidth: 80}, {xtype: 'textfield ', fieldLabel: 'Current latitude', id: 'flatout', name: 'flatout', msgTarget: 'day', allowBlank: false, labelWidth: 80}]}, {xtype: 'textfield ', fieldLabel: 'upload time', id: 'ftime', name: 'ftime', // yyyy-MM- Dd HH: mm: ssvalue: Ext. date. format (new Date (date. getFullYear (), date. getMonth (), date. getDate (), date. getHours (), date. getMinutes (), date. getSeconds (), ext_dateFormat), listeners: {'focal ': function () {WdatePicker ({dateFmt: dateFormat}) ;}}, {xtype: 'filefield ', id: 'fiupload', emptyText: 'click the right button to select a file! ', FieldLabel: 'select file', name: 'fiupload', buttonText: 'browse file', buttonConfig: {iconCls: 'upload-icons'}], buttons: [{text: 'save file', handler: function () {var writable ORM = this. up ('form '). getForm (); if (writable Orm. isValid () {mongoorm. submit ({type: 'ajax ', url: 'files/addData. action ', method: "POST", waitMsg:' uploading. Please wait... ', success: function (form, action) {Ext. msg. alert ('success', 'file uploaded successfully! ');}, Failure: function (form, action) {Ext. msg. alert ("Failure", "File Upload Failed") ;}}}}, {text: 'reupload', handler: function () {this. up ('form '). getForm (). reset () ;}}]}) ;});

Core background processing methods:

Private static final int BUFFER_SIZE = 16*1024; public String addData () throws Exception {Timestamp ts = new Timestamp (System. currentTimeMillis (); SimpleDateFormat df = new SimpleDateFormat ("yyyyMMddHHmmssSSS"); // set the date format ts = Timestamp. valueOf (this. ftime); System. out. println (ts); String nowtime = df. format (new Date (); System. out. println ("uploadFileName =" + this. fiuploadFileName); System. out. println ("UploadContentType =" + this. fiuploadContentType); System. out. println (nowtime); // upload -- the folder under wapps, used to store the image String toSrc = ServletActionContext. getServletContext (). getRealPath ("upload") + "/" + nowtime + getFileExp (this. fiuploadFileName); // use the time stamp as the file name String toFilename = nowtime + getFileExp (this. fiuploadFileName); String toSrcPath = ". /upload/"+ toFilename; String toinfo = this. finfo; Double tolo Ng133 = Double. parseDouble (this. flonglatitude); Double tolatitude = Double. parseDouble (this. flatitude); System. out. println ("original file name:" + this. fiuploadFileName); System. out. println ("file Description:" + toinfo); System. out. println ("Storage path:" + toSrcPath); System. out. println ("file name:" + toFilename); System. out. println ("Current longitude:" + tolongpolling); System. out. println ("Current dimension:" + tolatitude); File toFile = new File (toSrc); write File (this. fiupload, toFile); Files files = new Files (ts, toFilename, toSrcPath, toinfo, tolatitude, tolong.pdf); String result = filesService. addData (files); System. out. println (result); success = true; return SUCCESS;} private static void writeFile (File src, File dst) {System. out. println ("= file write ="); try {InputStream in = null; OutputStream out = null; try {in = new BufferedInputStream (new FileInputStr Eam (src), BUFFER_SIZE); out = new BufferedOutputStream (new FileOutputStream (dst), BUFFER_SIZE); byte [] buffer = new byte [BUFFER_SIZE]; while (in. read (buffer)> 0) {out. write (buffer) ;}} finally {if (null! = In) {in. close () ;}if (null! = Out) {out. close () ;}} catch (Exception e) {e. printStackTrace () ;}system. out. println ("= write successful! = ");}


Related Article

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.