首先说一下几个地方:

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. asp.net资料! (.NET) (ASP.NET)

    使用SqlBulkCopy类加载其他源数据到SQL表 在数据回发时,维护ASP.NET Tree控件的位置 vagerent的vs2005网站开发技巧 ASP.NET2.0小技巧--内部控件权限的实现 ...

  2. POJ 3264 Balanced Lineup 简单RMQ

    题目:http://poj.org/problem?id=3264 给定一段区间,求其中最大值与最小值的差. #include <stdio.h> #include <algorit ...

  3. 使用自定义《UIActivity》进行内容分享-b

    简介 这段时间有很多朋友都问我关于怎么去集成ShareSDK或者友盟社会化分享SDK的问题, 其实我想说, Apple一开始就提供了一个类, 供我们去使用分享了, 在iOS 6之后更加增强了这个类, ...

  4. 意犹未尽而来的第一篇Android 逆向

    游戏:咕噜王国大冒险 平台:android 目标: 1. 去除乱七八糟提示(本篇目标) 2. 去除google弹窗 3. 破解“all stages” 破文开始: 1. 使用APKIDE反编译:搜索字 ...

  5. JQuery自学代码---(一)

    /** * Created by wyl on 15-3-4. */ //Jquery是一个JavaScrioe库,它极大的简化了JavaScript编程 $(document).ready(func ...

  6. Word添加新编号

    要用到(1)(2),不想手写,但是word只有1.2.3和1)2)3),我就自定义哦.

  7. Eclipse怎样导入github上的项目

    国外有些比较好的源代码网站,经常需要从这些网站上导入项目到eclipse中,我最近就发现github.com这个网站上有很多开源项目.这里就以从github网站上导入项目到eclipse中为例来详细的 ...

  8. 17.1.1.2 Setting the Replication Slave Configuration

    17.1.1.2 Setting the Replication Slave Configuration 在一个复制slave, 你必须创建一个唯一的server ID,如果这个没有做,slave设置 ...

  9. 转:三十、Java图形化界面设计——布局管理器之BorderLayout(边界布局)

    http://blog.csdn.net/liujun13579/article/details/7772215 边界布局管理器把容器的的布局分为五个位置:CENTER.EAST.WEST.NORTH ...

  10. C++运行字符编码于MSVC和GCC之间的区别

    详细请参考这篇博文 http://blog.csdn.net/dbzhang800/article/details/7540905 运行字符编码就是指,当你源代码写下const char* p = & ...