起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2366|回复: 9

[处理中5] 为什么attachmentSimple上传图片到Cloudx5过几分钟后消失了

[复制链接]

31

主题

116

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
QQ
发表于 2017-8-21 17:56:01 | 显示全部楼层 |阅读模式
本帖最后由 developerML 于 2017-8-21 17:57 编辑

attachmentSimple组件上传图片到Cloudx5浏览图片正常,但是过几分钟后再打开app,上传的图片消失了,如图
IMG_20170820_081642.jpg
IMG_20170820_093414.jpg

88

主题

464

帖子

763

积分

高级会员

Rank: 4

积分
763
QQ
发表于 2017-8-21 18:03:38 | 显示全部楼层
你页面刷新了吧        没有data.save()也是白搭哦
回复 支持 反对

使用道具 举报

31

主题

116

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
QQ
 楼主| 发表于 2017-8-22 10:18:01 | 显示全部楼层
q2045377 发表于 2017-8-21 18:03
你页面刷新了吧        没有data.save()也是白搭哦

attachmentSimple绑定的data字段已保存,storeFileName,realFileName,ownerID已存到该字段了,如图显示
回复 支持 反对

使用道具 举报

88

主题

464

帖子

763

积分

高级会员

Rank: 4

积分
763
QQ
发表于 2017-8-22 10:49:42 | 显示全部楼层
developerML 发表于 2017-8-22 10:18
attachmentSimple绑定的data字段已保存,storeFileName,realFileName,ownerID已存到该字段了,如图显示 ...

你看看存储的文件夹有没有这个文件,,,没有的话就是没保存成功

如果有的话,,再看看自己的绑定的链接对不对,alert出看看,,是不是指向那个文件夹的文件,
回复 支持 反对

使用道具 举报

31

主题

116

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
QQ
 楼主| 发表于 2017-8-22 12:47:46 | 显示全部楼层
本帖最后由 developerML 于 2017-8-22 12:49 编辑
q2045377 发表于 2017-8-22 10:49
你看看存储的文件夹有没有这个文件,,,没有的话就是没保存成功

如果有的话,,再看看自己的绑定的链接 ...

本地测试在Wex5_v3.5\runtime\BaasServer\下已有文件夹和文件,提取出来服务器路径是/baas/x5/attachment/SimpleFileStore?realFileName=....&storeFileName=....&ownerID=...&opertateType=browse
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
35913
发表于 2017-8-23 17:02:18 | 显示全部楼层
F12打开浏览器的开发人员调试工具看看network中监控到图片的完整的url是什么
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

31

主题

116

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
QQ
 楼主| 发表于 2017-8-24 15:29:19 | 显示全部楼层
jishuang 发表于 2017-8-23 17:02
F12打开浏览器的开发人员调试工具看看network中监控到图片的完整的url是什么

type Exception report
message 执行Action:x5/attachment/SimpleFileStore失败,Action[x5/attachment/SimpleFileStore]执行失败,/usr/local/tomcat/lib/model/UI2/PaperlessInventoryTaking/photo/attachmentSimple/414/C7A70EF45C500001CC9C4D80A0E0116B (No such file or directory)


description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: 执行Action:x5/attachment/SimpleFileStore失败,Action[x5/attachment/SimpleFileStore]执行失败,/usr/local/tomcat/lib/model/UI2/PaperlessInventoryTaking/photo/attachmentSimple/414/C7A70EF45C500001CC9C4D80A0E0116B (No such file or directory)        com.justep.baas.servlet.BaasServlet.execService(Unknown Source)        com.justep.baas.servlet.BaasServlet.service(Unknown Source)
root cause
com.justep.baas.action.ActionException: Action[x5/attachment/SimpleFileStore]执行失败,/usr/local/tomcat/lib/model/UI2/PaperlessInventoryTaking/photo/attachmentSimple/414/C7A70EF45C500001CC9C4D80A0E0116B (No such file or directory)        com.justep.baas.action.Engine.execAction(Unknown Source)        com.justep.baas.action.Engine.execAction(Unknown Source)        com.justep.baas.servlet.BaasServlet.execService(Unknown Source)        com.justep.baas.servlet.BaasServlet.service(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.48 logs.



未标题-1 拷贝.jpg
回复 支持 反对

使用道具 举报

31

主题

116

帖子

259

积分

中级会员

Rank: 3Rank: 3

积分
259
QQ
 楼主| 发表于 2017-8-24 15:31:18 | 显示全部楼层
我不懂JAVA,请教是下面的代码哪里如何改


package x5;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

import com.alibaba.fastjson.JSONObject;
import com.justep.baas.action.ActionContext;

public class SimpleFileStore {

        public static JSONObject service(JSONObject params, ActionContext context) throws ServletException, IOException {
               
                HttpServletRequest request = (HttpServletRequest)context.get(ActionContext.REQUEST);
                HttpServletResponse response = (HttpServletResponse)context.get(ActionContext.RESPONSE);
                if(request.getMethod().equals("GET")){
                        doGet(request, response);
                }else if(request.getMethod().equals("POST")){
                        doPost(request, response);
                }
                return null;
        }
       
        static String docStorePath;
        static File docStoreDir;
       
        static{
                System.out.println();
                String baasPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + ".." + File.separator + "..";
        //        String baasPath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
        //        System.out.println(baasPath);
                docStorePath = baasPath + File.separator + "model" +File.separator + "UI2" +File.separator + "PaperlessInventoryTaking" +File.separator+"photo" + File.separator + "attachmentSimple";
        //        System.out.println(docStorePath);
                File file = new File(docStorePath);
                //兼容以前存储目录
                if(file.exists() && file.isDirectory()){
                        docStoreDir = file;   
                        //file.mkdirs();
                }
                //docStoreDir = file;
        }
       
       
        public static File getDocStoreDir(HttpServletRequest request) {
                if(docStoreDir == null){
                        ServletContext context = request.getSession().getServletContext();
                        String path = context.getRealPath("/");
                        System.out.println(path);
                        docStorePath =  path + "model/UI2/PaperlessInventoryTaking/photo/attachmentSimple/";
                        File file = new File(docStorePath);
                        if(!file.exists()){
                                file.mkdirs();
                        }
                        docStoreDir = file;
                }
                return docStoreDir;
        }
       
       
        /**
                get为获取文件 浏览或者下载
        **/
        private static void doGet(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                getDocStoreDir(request);
                String operateType = request.getParameter("operateType");
                if("copy".equals(operateType)){
                        copyFile(request,response);
                }else{
                        getFile(request,response);
                }
        }
       
       
        private static void copyFile(HttpServletRequest request,
                        HttpServletResponse response) throws IOException {
                String ownerID = request.getParameter("ownerID");
                String targetOwnerID = request.getParameter("targetOwnerID");
                String storeFileName = request.getParameter("storeFileName");
                File file = new File(docStorePath + File.separator +ownerID + File.separator + storeFileName);
                File targetFile = new File(docStorePath + File.separator + targetOwnerID + File.separator + storeFileName);
                FileUtils.copyFile(file, targetFile);
        }
       
       
        private static final int BUFFER_SIZE = 32768 * 8;
        private static void getFile(HttpServletRequest request,
                        HttpServletResponse response) throws IOException {
                String ownerID = request.getParameter("ownerID");
                String realFileName = URLEncoder.encode(request.getParameter("realFileName"),"utf-8");
                String storeFileName = request.getParameter("storeFileName");
                String operateType = request.getParameter("operateType");
                /*String fileSize = request.getParameter("fileSize");*/
               
                File file = new File(docStorePath + File.separator +ownerID + File.separator + storeFileName);
                FileInputStream fis = new FileInputStream(file);
               
                /*response.setContentType(mimeType);*/
        /*response.setHeader("Content-Length", String.valueOf(part.getSize()));*/
                response.setHeader("Cache-Control", "pre-check=0, post-check=0, max-age=0");
               
                String fileNameKey = "filename";
                /*UserAgent ua = com.justep.ui.util.NetUtils.getUserAgent(request);
                if(Browser.FIREFOX.equals(ua.getBrowser().getGroup())){
                        fileNameKey = "filename*";
                }*/
                if("download".equals(operateType)){
                        response.addHeader("Content-Disposition", "attachment; "+fileNameKey+"=\"" + realFileName + "\"");
                }else{
                        response.addHeader("Content-Disposition", "inline; "+fileNameKey+"=\"" + realFileName + "\"");
                }
               
                OutputStream os = response.getOutputStream();
        byte[] buffer = new byte[BUFFER_SIZE];
        try {
            int read;
            while ((read = fis.read(buffer)) != -1) {
                    os.write(buffer, 0, read);
            }
        } finally {
            fis.close();
        }
        }

        /**
                post为上传
        **/
        protected static  void doPost(HttpServletRequest request, HttpServletResponse response)
                        throws ServletException, IOException {
                getDocStoreDir(request);
                String contentType = request.getContentType();
                try {
                        if("application/octet-stream".equals(contentType)){
                                storeOctStreamFile(request,response);
                        }else if(contentType !=null && contentType.startsWith("multipart/")){
                                storeFile(request,response);
                        }else{
                                throw new RuntimeException("not supported contentType");
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                        throw new IOException("storeFile异常");
                }
                response.getWriter().write("");
        }

        private static void storeOctStreamFile(HttpServletRequest request,
                        HttpServletResponse response) throws IOException {
                InputStream in = null;
                FileOutputStream storeStream = null;
                try{
                        String ownerID = request.getParameter("ownerID");
                        String storeFileName = request.getParameter("storeFileName");
                       
                        in = request.getInputStream();
                        String storePath = docStorePath + File.separator + ownerID;
                        getOrCreateFile(storePath);
                        File toStoreFile = new File(storePath + File.separator + storeFileName);
                storeStream = new FileOutputStream(toStoreFile);
                IOUtils.copy(in, storeStream);
                }finally{
                        IOUtils.closeQuietly(in);
                        IOUtils.closeQuietly(storeStream);
                }
        }
       
        private static File getOrCreateFile(String path) {
                File storeDir = new File(path);
        if(!(storeDir.exists() && storeDir.isDirectory())){
                storeDir.mkdirs();
        }
        return storeDir;
        }
       
        public static List<FileItem> parseMultipartRequest(HttpServletRequest request) throws FileUploadException{
                DiskFileItemFactory factory = new DiskFileItemFactory();

                ServletContext servletContext = request.getSession().getServletContext();
                File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir");
                factory.setRepository(repository);

                // Create a new file upload handler
                ServletFileUpload upload = new ServletFileUpload(factory);

                // Parse the request
                @SuppressWarnings("unchecked")
                List<FileItem> items = upload.parseRequest(request);
                return items;
        }
       
        private static void storeFile(HttpServletRequest request,
                        HttpServletResponse response) throws Exception {
                HashMap<String,String> params = new HashMap<String,String>();
                List<FileItem> items =  parseMultipartRequest(request);
                Iterator<FileItem> iter = items.iterator();
                FileItem fileItem = null;
                while (iter.hasNext()) {
                    FileItem item = iter.next();
                    if (item.isFormField()) {
                            String name = item.getFieldName();
                    String value = item.getString();
                        params.put(name, value);
                    } else {
                            /*String fieldName = item.getFieldName();
                        String fileName = item.getName();
                        String contentType = item.getContentType();
                        boolean isInMemory = item.isInMemory();
                        long sizeInBytes = item.getSize();*/
                            fileItem = item;
                    }
                }
                if(fileItem != null){
                        String storePath = docStorePath + File.separator + params.get("ownerID");
                File storeDir = new File(storePath);
                if(!(storeDir.exists() && storeDir.isDirectory())){
                        storeDir.mkdirs();
                }
                File toStoreFile = new File(storePath + File.separator + params.get("storeFileName"));
                fileItem.write(toStoreFile);
                }
                               
        }
       
       
       
       
       
       
}
回复 支持 反对

使用道具 举报

发表于 2017-8-25 16:38:25 | 显示全部楼层
developerML 发表于 2017-8-24 15:31
我不懂JAVA,请教是下面的代码哪里如何改

你好楼主,这个问题需要我在本地环境进行问题重现,所以会花费较长时间,请你耐心等待,我完成后会第一时间反馈结果,谢谢!

qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

发表于 2017-8-25 17:07:19 | 显示全部楼层
developerML 发表于 2017-8-24 15:31
我不懂JAVA,请教是下面的代码哪里如何改

你好楼主,这个特性目前版本不支持,已作为产品功能建议提交(内部编号:2017082500003),感谢楼主的支持与配合。

qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-4-20 01:54 , Processed in 0.065554 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表