wifi下上传文件

功能:流量下上传文件的名字,wifi下再自动上传真实文件


**public String addAttachs() throws Exception{
    dataMap = new HashMap<String, Object>();
    String newname = "";
    File[] newfiles = getFile();
    System.out.println(type);
    System.out.println(fileFileName[0]);
    if(file!=null){
        Fileupload Fileupload= new Fileupload();
        newname = Fileupload.uploadFile(newfiles, fileFileName,type);
        System.out.println(newname+"上传OK");
    }
    else{
        Fileupload Fileupload= new Fileupload();
        newname = Fileupload.uploadFileNewName( fileFileName);
        System.out.println(newname+"流量下上传OK");
    }
        //wifi 下 上传   ,流量下上传个newname
    dataMap.put("newname", newname);
    dataMap.put("filename", StringUtil.array2string(fileFileName));
    return SUCCESS;
}**
**///wifi下下载     填原newNames
public String addAttachsWifi() throws Exception{
    dataMap = new HashMap<String, Object>();
    File[] newfiles = getFile();
    String newNames=getNewNames();
    System.out.println(type);
    if(file!=null&&newNames!=null){
        Fileupload Fileupload= new Fileupload();
        Fileupload.uploadFileNewName2(newfiles, newNames,type);
        System.out.println(newNames+"wifi下上传OK");
    }
    else{
        System.out.println(newNames+"wifi下上传失败");
    }
        //wifi 下 上传   ,流量下上传个newname
    dataMap.put("newname", newNames);
    dataMap.put("filename", StringUtil.array2string(fileFileName));
    return SUCCESS;
}**

、、

/*
* wifi 下上传newname
*/

public String uploadFileNewName(String[] filenames)
{
    ArrayList<String> newfiles = new ArrayList<String>();

    for(int j=0;j<filenames.length;j++){
        String[] split = filenames[j].split(";");
        if (split.length > 0) {
            for (int i = 0; i < split.length; i++) {
                String aaa = NewIdUtil.getNewIdUtil().getNewId()
                        + split[i].substring(split[i].lastIndexOf("."),
                                split[i].length());
                newfiles.add(aaa);
            }
        }
    }
    return StringUtil.turnString3(newfiles);
}
//有 wifi下下载
public String uploadFileNewName2(File[] files, String newname, String type) throws IOException{
    String root = "";
    if("picture".equals(type)){
        root = ServletActionContext.getServletContext().getRealPath("/systemfile/picture");
    }else if("file".equals(type)){
        root = ServletActionContext.getServletContext().getRealPath("/systemfile/attach");
    }else if("record".equals(type)){
        root = ServletActionContext.getServletContext().getRealPath("/systemfile/record");
    }
    String []filenames=newname.split(";");
    ArrayList<String> newfiles = new ArrayList<String>();
    if (filenames.length > 0) {
        for (int i = 0; i < filenames.length; i++) {
            String aaa=filenames[i];
            FileOutputStream fos = new FileOutputStream(root+"/"+aaa);
            FileInputStream fis = new FileInputStream(files[i]);
            byte[] buffer = new byte[1024];
            int len = 0;
            while ((len = fis.read(buffer)) > 0) {
                fos.write(buffer, 0, len);
            }
            fis.close();
            fos.close();
            /* 这儿填写你转化后的图片存放的文件夹 */
            ImageChange r = new ImageChange();
            if("picture".equals(type)){
                if(ImageUtil.isImage(new File(root +"/"+ aaa))){
                    int width = Integer.valueOf(MyProperties.getByKey("width"));
                    int width2 = Integer.valueOf(MyProperties.getByKey("width2"));
                    /* 这个参数是要转化成的宽度 */
                    BufferedImage f = r.getBufferedImage(root +"/"+ aaa);
                    r.writeHighQuality(r.zoomImage(f, width), root +"1/", aaa);
                    r.writeHighQuality(r.zoomImage(f, width2), root +"2/", aaa);
                    f.flush();
                }
            }
        }
    }
    return StringUtil.turnString3(newfiles);
}

主要思路是如果流量下addAttachs 方法只接受参数fileFileName ,在uploadFileNewName方法里会生成newname,再在addAttachsWifi里传入这个newname,以及file,及type 再进行上传

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值