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 ...
随机推荐
- bss段为什么需要初始化?
我们都知道bss段需要初始化,但是这是为什么呢? 通过浏览资料,我们都会发现,bss段是不会出现在程序下载文件(*.bin *.hex)中的,因为全都是0.如果把它们出现在程序下载文件中,会增加程序下 ...
- ajax error函数
老是去百度 还是自己记下来吧 $.ajax({ url: '/AJAX请求的URL', success: function (data) { alert(data); }, error: functi ...
- EF5.0 对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性
使用asp.net+EF5.0练习的时候,遇到这样一个问题: 对一个或多个实体的验证失败.有关详细信息,请参见“EntityValidationErrors”属性 但是感到很疑惑,去百度,说是关闭EF ...
- iOS开发之国际化
iOS 国际化.根据系统不同的语言自动切换. 首先.选择项目 Add new file -->iOS -->Resource -->Strings File . 命名为Locali ...
- Pentaho Data Integration Step: BD Procedure Call
官网连接:http://wiki.pentaho.com/display/EAI/Call+DB+Procedure 描述 调用数据库存储过程步骤允许用户执行一个数据库存储过程,并且得到结果.存储过程 ...
- How to new a screen in linux
screen -R -D: create a screen Ctrl + A & Ctrl + D: leave a screen
- bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥
1914: [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 272 Sol ...
- [原博客] POI系列(5)
正规.严谨.精妙. -POI BZOJ 2213 : [Poi2011]Difference 如果我们每次枚举两个字母最大最小情况时,很容易想到写出代码里注释的样子.这样是26*26*n的,我们发现枚 ...
- CRC算法及C实现
一.CRC算法原理 CRC校验的基本思想是利用线性编码理论,在发送端根据要传送的k位二进制码序列,以一定的规则产生一个校 验用的监督码(既CRC码)r位,并附在信息后边,构成一个新的二进制码序列数 ...
- Tabhost嵌套以及Tab中多个Activity跳转的实现
做了一个demo,先看看效果图: 源码 如下: () DoubleTabHost package yy.android.tab; import android.app.TabActivity; imp ...