阿里云OSS配置demo


表单直传
<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <meta charset="utf-8">
  <title>editor示范例</title>

  <script>
    function send_request() {
      var xmlhttp = new XMLHttpRequest();

      // serverUrl是 用户获取 '签名和Policy' 等信息的应用服务器的URL,请将下面的IP和Port配置为您自己的真实信息。
      // serverUrl = 'http://88.88.88.88:8888/aliyun-oss-appserver-php/php/get.php'
      serverUrl = 'https://xxxxx'

      xmlhttp.open("GET", serverUrl, false);
      xmlhttp.send(null);
      return xmlhttp.responseText;
    };


    function send_data() {

      body = send_request()
      var obj = eval("(" + body + ")");
      host = obj['host']
      policyBase64 = obj['policy']
      accessid = obj['accessid']
      signature = obj['signature']
      expire = parseInt(obj['expire'])
      callbackbody = obj['callback']
      key = obj['dir']
      // return host;

      var data = new FormData();
      data.append("key", key + "1.jpg");
      data.append("OSSAccessKeyId", accessid);
      data.append("signature", signature);
      data.append("success_action_status", "200"); //让服务端返回200,不然,默认会返回204!!!重要
      data.append("policy", policyBase64);
      data.append("file", document.getElementById('fff').files[0], "file1");

      var xhr = new XMLHttpRequest();
      xhr.open("POST", "https://xxx.oss-cn-hangzhou.aliyuncs.com");
      xhr.send(data);

    };
  </script>
</head>
<body>
  <input id="fff" type="file" />
  <input onclick="send_data()" onclick="send_data()" type="submit" />
</body>

</html>
0

【阿里云OSS配置demo隶属于分类: 技术工具

它起初由本站用户:刘欣Eden于3年前 创建。

该内容的链接是:

目录