Sae 上传文件到Storage
来源:互联网 发布:网络电视无信号 编辑:程序博客网 时间:2024/06/05 18:14
首先说一下几个地方:
1.上传使用ss.upload("domin域名","源地址","目标地址,也就是storage的地址");如果要上传到storage某一个具体的文件夹下目标地址写为"upload/"+filename;文件就上传到了upload目录下。
2.storage下面所有文件的路径是http://myapp-mybucket.stor.sinaapp.com/path/file.txt 前面是myapp是应用的名字,这个路径可以通过
String realPath = ss.getUrl("域名", “上面的目标路径”); 就可以得到这个全网路径
3.使用commons-fileupload上传组件时,先把文件写到一个临时路径里,然后再写回storage就好了。
下面是java代码:
<pre name="code" class="java">private void userSave(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {FileItemFactory factory=new DiskFileItemFactory();ServletFileUpload upload=new ServletFileUpload(factory);List<FileItem> items=null;try {items=upload.parseRequest(request);} catch (FileUploadException e) {// TODO Auto-generated catch blocke.printStackTrace();}Iterator<FileItem> itr=items.iterator();HttpSession session=request.getSession();User user=(User)session.getAttribute("currentUser");//上传到Storage之后的真是路径String realPath=user.getImageName();String imageName=user.getImageName();boolean imageChange=false;<span style="white-space:pre"></span>while(itr.hasNext()){ <span style="white-space:pre"></span> FileItem item=(FileItem)itr.next(); <span style="white-space:pre"></span> if(!item.isFormField()){ <span style="white-space:pre"></span> try{ <span style="white-space:pre"></span> imageName=DateUtil.getCurrentDateStr(); <span style="white-space:pre"></span> //带后缀的文件名 <span style="white-space:pre"></span> imageName=imageName+"."+item.getName().split("\\.")[1]; <span style="white-space:pre"></span> user.setImageName(imageName); <span style="white-space:pre"></span> //String filePath=PropertiesUtil.getValue("imagePath")+imageName+"."+item.getName().split("\\.")[1]; <span style="white-space:pre"></span> String folder=PropertiesUtil.getValue("imagePath"); <span style="white-space:pre"></span> String filePath=session.getServletContext().getRealPath(folder)+"/"+imageName; <span style="white-space:pre"></span> <span class="comment" style="margin: 0px; padding: 0px; border: none; color: rgb(0, 130, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px;">//前面的部分只需要按正常的上传来写就可以了 filePath只是一个临时文件</span><span style="margin: 0px; padding: 0px; border: none; font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px;"> </span>
<span style="white-space:pre"></span> <span style="color:#ff0000;">item.write(new File(filePath));</span> // 上传完毕后 使用SaeStorage往storage里面写 SaeStorage ss = new SaeStorage(); // 使用upload方法上传到域domain下,此处本人的是onway <span style="color:#ff0000;">ss.upload("onway", filePath, <span style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248);">"upload/"</span>+imageName);</span> // 获取上传后的图片路径 realPath = <span style="color:#ff0000;">ss.getUrl</span>("onway", <span style="color: rgb(0, 0, 255); font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248);">"upload/"</span>+imageName); // System.out.println(realPath);}catch(Exception e){ e.printStackTrace();}}}
0 0
- SAE上传文件到storage
- Sae 上传文件到Storage
- SAE-上传本地图片到SAE的Storage(php版)
- 【ThinkPHP学习】ThinkPHP结合KindEditor SAE storage上传文件图片
- WordPress在SAE环境上传文件至storage存储
- 在sae中,怎么将图片上传到storage的二级目录的代码?
- Django在新浪SAE中使用storage服务实现文件上传保存
- 【ThinkPHP学习】ThinkPHP upload与SAE storage结合,实现文件上传
- sae上传文件
- SAE利用storge上传文件
- SAE文件上传与下载
- SAE Storage + Android微信内置浏览器图片上传解决方案
- 使用php原生代码上传图片至SAE的STORAGE
- 上传我的项目到SAE
- django【本地导出的sql文件上传到SAE出现错误】
- SAE storage linux管理
- SAE Storage 实例1
- [SAE学习笔记]Storage尝鲜
- 设计一个算法,判断给定的一棵二叉树是否是二叉排序树(二叉树的所有关键字均为正整数)
- Ext.net 关于datefield 控件
- 自定义iOS列表索引控件
- Unity 坐标转换 世界坐标转换到NGUI坐标
- iOS应用内购买报错:invalidProductIdentifiers
- Sae 上传文件到Storage
- error LNK2001: 无法解析的外部符号 "void * __cdecl operator new(unsigned int)"
- 非阻塞/异步(epoll) openssl
- java.io.Serializable浅析
- 关于使用Java代码解决兔子问题
- android 能ping通,但是不能 unable to connect to ip
- android DDMS 连接真机(己ROOT),用file explore看不到data/data文件夹的解决办法 .
- 限定EditText只能输入两位小数的两种方式
- 基于js的前端开发框架对比