Sae 上传文件到Storage
首先说一下几个地方:
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 block
e.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();
}
}
}
Sae 上传文件到Storage的更多相关文章
- SAE上传文件到storage
还有什么比代码更清晰的讲解 html代码: 一定需要下面这个: method="post" enctype="multipart/form-data" < ...
- kindeditor在sae上传文件修改,适合php
kindeditor在sae上传文件修改,适合php 当前位置: 首页 > 论坛 > 经验共享 用户登录 新用户注册 主题: kindeditor在sae上传文件修改,适合ph ...
- [Azure Storage]使用Java上传文件到Storage并生成SAS签名
Azure官网提供了比较详细的文档,您可以参考:https://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to ...
- 上传文件到新浪云Storage的方法
上传文件到新浪云Storage的方法,兼容本地服务器 if (!empty($_FILES['sharepic']['name'])){ $tmp_file = $_FILES['sharepic'] ...
- SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET
SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET SAE利用storge上传文件
- 【阿里云产品公测】ACE下上传文件永久存储实践
本帖主要内容: ;$,=VB:' 在阿里云的ACE下,我是如何实现让上传的文件永久保存的? ,%"!8T 本文以PHP为例,具体知识点如下: WD# 96V 第一,扩展服务“存储 ...
- [SDK2.2]Windows Azure Storage (16) 使用WCF服务,将本地图片上传至Azure Storage (上) 客户端代码
<Windows Azure Platform 系列文章目录> 前一章我们完成了服务器端的代码,并且已经发布到了Windows Azure云端. 本章我们将实现客户端的代码,客户端这里我们 ...
- JAVA模拟HTTP post请求上传文件
在开发中,我们使用的比较多的HTTP请求方式基本上就是GET.POST.其中GET用于从服务器获取数据,POST主要用于向服务器提交一些表单数据,例如文件上传等.而我们在使用HTTP请求时中遇到的比较 ...
- FileUpload 上传文件,并实现c#使用Renci.SshNet.dll实现SFTP文件传输
fileupload上传文件和jquery的uplodify控件使用方法类似,对服务器控件不是很熟悉,记录一下. 主要是记录新接触的sftp文件上传.服务器环境下使用freesshd搭建好环境后,wi ...
随机推荐
- BZOJ2191Splite
Description 给两个多边形,问否在平移旋转不翻转不重叠的情况下拼成一个凸多边形. Input 每组第一行一个数N表示第一个多边形的顶点数,下接N行按顺序(逆/顺时针)给出顶点坐标,再下一行给 ...
- Codeforces Round #316 div2
一场充满血腥hack之战!!! Problem_A: 题意: n个候选人在m个城市进行投票,每个城市选出票数最多的一个候选人为城市候选人,如果票数相同,则取编号小的候选人. 再从这m个城市候选人中选出 ...
- Sql中的datetime类型的空值和c#中的DateTime的空值的转换方法
[一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/3412796.html] 在NET 2.0以上版本提供了一种新的方法 就是加问号,DateTim ...
- Windows.document对象
一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:var a =docunment.getElementById("i ...
- 【CF】323 Div2. D. Once Again...
挺有意思的一道题目.考虑长度为n的数组,重复n次,可以得到n*n的最长上升子序列.同理,也可以得到n*n的最长下降子序列.因此,把t分成prefix(上升子序列) + cycle(one intege ...
- 【session】
users.json { "tobi": { "password": "ferret", "name": "T ...
- Navigation Drawer(导航抽屉)
目录(?)[-] 创建一个导航抽屉 创建抽屉布局 初始化抽屉列表 处理导航项选点击事件 监听导航抽屉打开和关闭事件 点击应用图标来打开和关闭导航抽屉 创建一个导航抽屉 导航抽屉是一个位于屏幕左侧边缘用 ...
- Android Loader详解四:回调及完整例子
onLoadFinished 这个方法是在前面已创建的装载器已经完成其加载过程后被调用.这个方法保证会在应用到装载器上的数据被释放之前被调用.在此方法中,你必须删除所有对旧数据的使用(因为它将很快会被 ...
- Castle学习系列之二:Castle配置
说明:本系列文章参考自李会军先生的Castle 开发系列文章,然后记录自己在学习时遇到的一些问题,记录之. 主要内容 1.Castle配置学习 2.初始化配置 Castle配置学习 <?xml ...
- SDPLR的安装过程(matlab)
SDPLR 半正定规划优化工具的安装过程很简单,只要按照SDPLR 1.03-beta User's Guide (short version).pdf的介绍安装就可以. 运行在下载的工具包目录里运行 ...