首先说一下几个地方:

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的更多相关文章

  1. SAE上传文件到storage

    还有什么比代码更清晰的讲解 html代码: 一定需要下面这个: method="post" enctype="multipart/form-data" < ...

  2. kindeditor在sae上传文件修改,适合php

    kindeditor在sae上传文件修改,适合php 当前位置: 首页  > 论坛  > 经验共享 用户登录   新用户注册   主题: kindeditor在sae上传文件修改,适合ph ...

  3. [Azure Storage]使用Java上传文件到Storage并生成SAS签名

    Azure官网提供了比较详细的文档,您可以参考:https://azure.microsoft.com/en-us/documentation/articles/storage-java-how-to ...

  4. 上传文件到新浪云Storage的方法

    上传文件到新浪云Storage的方法,兼容本地服务器 if (!empty($_FILES['sharepic']['name'])){ $tmp_file = $_FILES['sharepic'] ...

  5. SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET

    SAE利用storge上传文件 - myskies的专栏 - 博客频道 - CSDN.NET SAE利用storge上传文件

  6. 【阿里云产品公测】ACE下上传文件永久存储实践

    本帖主要内容: ;$,=VB:'   在阿里云的ACE下,我是如何实现让上传的文件永久保存的? ,%"!8T   本文以PHP为例,具体知识点如下: WD# 96V   第一,扩展服务“存储 ...

  7. [SDK2.2]Windows Azure Storage (16) 使用WCF服务,将本地图片上传至Azure Storage (上) 客户端代码

    <Windows Azure Platform 系列文章目录> 前一章我们完成了服务器端的代码,并且已经发布到了Windows Azure云端. 本章我们将实现客户端的代码,客户端这里我们 ...

  8. JAVA模拟HTTP post请求上传文件

    在开发中,我们使用的比较多的HTTP请求方式基本上就是GET.POST.其中GET用于从服务器获取数据,POST主要用于向服务器提交一些表单数据,例如文件上传等.而我们在使用HTTP请求时中遇到的比较 ...

  9. FileUpload 上传文件,并实现c#使用Renci.SshNet.dll实现SFTP文件传输

    fileupload上传文件和jquery的uplodify控件使用方法类似,对服务器控件不是很熟悉,记录一下. 主要是记录新接触的sftp文件上传.服务器环境下使用freesshd搭建好环境后,wi ...

随机推荐

  1. Java String.contains()方法(转载)

    Java String.contains()方法 Java String.contains()方法用法实例教程, 返回true,当且仅当此字符串包含指定的char值序列 描述 java.lang.St ...

  2. ubuntu杂记

    安装ssh: sudo apt-get install openssh-server sudo /etc/init.d/ssh start 将主机中vmware8的网络改为自动获取ip,就可以ping ...

  3. C# string LastIndexOf()

    IndexOf(“FindText",start,len) 中的Start和Len是从左往右数的 LastIndexOf(“FindText",start,len)中的则是从右往左 ...

  4. 小Z的创业经历 谢谢支持

    写这篇文章的目的是跟大家分享下创业的一些想法,经历.希望对你有所帮助或有所思考.  我想用6篇文章介绍下前期创业经历 1.怎么创业了? 2.万事开头难,怎么开始呢? 3.我们的系统详情(上) 4.我们 ...

  5. Response.Redirect:无法在发送 HTTP 标头之后进行重定向

    URL:http://blog.163.com/asp_neter/blog/static/17510918820107258107558/ 错误出现语句:“Response.Redirect(&qu ...

  6. C#方法定义和调用-2

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  7. bzoj 2401: 陶陶的难题I 数论

    2401: 陶陶的难题I Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 24[Submit][Status] Descript ...

  8. bzoj 1200: [HNOI2005]木梳 DP

    1200: [HNOI2005]木梳 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 266  Solved: 125[Submit][Status] ...

  9. duilib入门简明教程 -- VS环境配置(2) Alberl

      既然是入门教程,那当然得基础点,因为搜索duilib相关资料时,发现有些小伙伴到处都是编译错误,以及路径配置错误等等,还有人不知道SVN,然后一个个文件手动下载的.     其实吧,duilib的 ...

  10. svn删除目录后提交显示Item 'XXXX' is out of date解决方法

    1.在要删除的目录上执行 svn 的 Delete 2.来到要删除目录的上级目录,执行更新操作.  3.找到要删除的目录,会显示冲突状态,在这个目录上执行Resolved.  4.在这个要删除的目录上 ...