java项目,跟官网DEMO一样 前端用的plupload组件 火狐浏览器没有问题 IE内核的浏览器每次打开后第一个上传的文件都会失败 关闭浏览器重新打开就又会失败一次
报这个错误
-------------------------
-------------------------
package com.demo.demo;
import java.io.IOException;
import java.sql.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.utils.BinaryUtil;
import com.aliyun.oss.model.MatchMode;
import com.aliyun.oss.model.PolicyConditions;
import junit.framework.Assert;
import net.sf.json.JSONObject;
@WebServlet(asyncSupported = true)
public class PostObjectPolicy extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 5522372203700422672L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String endpoint = "oss-cn-hangzhou.aliyuncs.com";
String accessId = "***";
String accessKey = "***";
String bucket = "***";
String host = "http://" + bucket + "." + endpoint;
OSSClient client = new OSSClient(endpoint, accessId, accessKey);
try {
//System.out.println(System.currentTimeMillis());
String dir = "user-dir";
long expireTime = 30;
long expireEndTime = System.currentTimeMillis() + expireTime * 1000;
Date expiration = new Date(expireEndTime);
PolicyConditions policyConds = new PolicyConditions();
policyConds.addConditionItem(PolicyConditions.COND_CONTENT_LENGTH_RANGE, 0, 1048576000);
policyConds.addConditionItem(MatchMode.StartWith, PolicyConditions.COND_KEY, dir);
String postPolicy = client.generatePostPolicy(expiration, policyConds);
byte[] binaryData = postPolicy.getBytes("utf-8");
String encodedPolicy = BinaryUtil.toBase64String(binaryData);
String postSignature = client.calculatePostSignature(postPolicy);
Map<String, String> respMap = new LinkedHashMap<String, String>();
respMap.put("accessid", accessId);
respMap.put("policy", encodedPolicy);
respMap.put("signature", postSignature);
//respMap.put("expire", formatISO8601Date(expiration));
respMap.put("dir", dir);
respMap.put("host", host);
respMap.put("expire", String.valueOf(expireEndTime / 1000));
JSONObject ja1 = JSONObject.fromObject(respMap);
//JSONArray ja1 = JSONArray.fromObject(respMap);
System.out.println(ja1.toString());
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET, POST");
response(request, response, ja1.toString());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
private void response(HttpServletRequest request, HttpServletResponse response, String results) throws IOException {
String callbackFunName = request.getParameter("callback");
if (callbackFunName==null || callbackFunName.equalsIgnoreCase(""))
response.getWriter().println(results);
else
response.getWriter().println(callbackFunName + "( "+results+" )");
response.setStatus(HttpServletResponse.SC_OK);
response.flushBuffer();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "GET, POST");
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。