首页 > 其他分享 >七牛云存储____七牛js直接上传图片

七牛云存储____七牛js直接上传图片

时间:2023-09-13 18:03:20浏览次数:46  
标签:七牛云 && formData js 七牛 xhr token key var


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

</head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow">
<meta name="googlebot" content="noindex, nofollow">


<script type="text/javascript" src="jsJustUpload/jquery-1.9.1.js"></script>
<script type="text/javascript" src="jsJustUpload/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css"	href="jsJustUpload/jquery-ui.css">

<title>七牛云存储 | 上传凭证</title>


<script type="text/javascript">
	//改函数要求浏览器必须要支持html5
	function jsJustUpload(f, token, key) {
		var Qiniu_UploadUrl = "http://up.qiniu.com";
		var xhr = new XMLHttpRequest();
		xhr.open('POST', Qiniu_UploadUrl, true);
		var formData= new FormData();
		if (key !== null && key !== undefined){
			formData.append('key', key);
		}
		formData.append('token', token);
		formData.append('file', f);
		xhr.onreadystatechange = function(response) {
			if (xhr.readyState == 4 && xhr.status == 200&& xhr.responseText != "") {
				var blkRet = JSON.parse(xhr.responseText);
				$("#dialog").html("复制连接直接访问_:http://oleco2u3s.bkt.clouddn.com/" + blkRet.key).dialog();
			} else if (xhr.status != 200 && xhr.responseText) {
				concole.log("服务传输异常!!");
			}
		};
		xhr.send(formData);
	}
	function test() {
		var f = $("#file")[0].files[0];
		var token =$("#token").val();
		var key = $("#key").val();
		jsJustUpload(f, token, key);
	}
</script>

</head>

<body>
	<form action="">
		<ul>
			<li>
			token:<input id="token" name="token" class="ipt" value="1o90vmY9OmRcueIeIeFBID6q2uy8peFiFBxpnM78:rdalpapK8yThJayH3FakQwqQbp8=:eyJzY29wZSI6InRlc3QiLCJkZWFkbGluZSI6MTYwNTA2NDI3MX0=">
			</li>
			<li>
				key:<input id="key" name="key"	class="ipt" value="<%=new Date().getTime()+".jpg"%>">
			</li>
			<li>
				照片:<input id="file" name="file"	class="ipt" type="file">
			</li>
			<li>
				<input id="btn_upload" type="button" value="提交" οnclick="test();">
			</li>
		</ul>
	</form>
	<div id="dialog" title="上传成功"></div>
</body>
</html>

//源码包地址

http://oleco2u3s.bkt.clouddn.com/jsupload.rar 

//运行结果

七牛云存储____七牛js直接上传图片_js图片上传

标签:七牛云,&&,formData,js,七牛,xhr,token,key,var
From: https://blog.51cto.com/ratelcloud/7462902

相关文章

  • 七牛云存储____官方SDK集成开发
    packagecom.scdn.qnscdn;/***七牛常理配置**@authorGod待整理好配到config文件里*ACCESSKEY这是我个人申请的一个测试的号everyonecanuseingit*SECRETKEY*/publicclassQnConstant{ //设置好账号的ACCESS_KEY和SECRET_KEY publicstaticfinalS......
  • 七牛云存储____图片转Base64串上传
    packagecom.scdn.qnscdn;/***七牛常理配置**@authorGod待整理好配到config文件里*ACCESSKEY这是我个人申请的一个测试的号everyonecanuseingit*SECRETKEY*/publicclassQnConstant{ //设置好账号的ACCESS_KEY和SECRET_KEY publicstaticfinalS......
  • JSNeedAttention
    JSAttentionpush返回的是数组增加后的长度!!!对象名可变setFieldsValue({[`bank${index}`]:val});判断是否空对象Object.keys(obj);JSON.stringify(obj)!=="{}";还有$.isEmptyObject(data2);Object.getOwnPropertyNames(data3);//和Object.keys类似关闭标签替......
  • 谷歌浏览器json格式化插件安装
    在前端开发中,经常需要处理json格式数据,方便查看和调试。而chrome浏览器提供了很多插件来帮助我们更方便地处理json数据,今天我们就来介绍一款非常方便的json格式化插件——JSONFormatter。插件安装该插件可以在ChromeWebStore中直接下载和安装,也可以通过浏览器插件商店进行安装。......
  • Jmeter BeanShell, 读取HTTP请求返回的JSON,并将其存到文件中
    1、创建BeanShellSampler将fastjson-1.2.30.jar放到Jmeter安装目录\lib下 importjava.io.*;importcom.alibaba.fastjson.JSONObject;importjava.io.IOException;importjava.io.File;importjava.io.FileOutputStream;importjava.io.FileWriter;privatestat......
  • JScript判断图片是否存在
    //判断图片是否存在functioncheckImgExists(imgurl){  varImgObj=newImage();//判断图片是否存在  ImgObj.src=imgurl;  //存在图片  if(ImgObj.fileSize>0||(ImgObj.width>0&&ImgObj.height>0)){    alert("true");  ......
  • C# JSON字符串转带头(声明)XML字符串
     privatestringConverXml(stringmemberId,intcode,stringmsg)    {      varresp=new{authenticate=new{member_id=memberId,status_code=code,message=msg}};      varjsonstr=JsonConvert.SerializeObject(re......
  • 创建mixin.js文件,引入表格分页
    //前端分页consttableFrontEndPaging={data(){return{currpage:1,page_size:10,page_list:[10,20,50],currentPage:null,header_cell_style:{background:'#C0C4CC',color:'#303133',borderColor:&#......
  • Java树形菜单_轻量级js树形插件_jsTree树形插件
    //插件效果//代码<!DOCTYPEhtml><html><head><title>JS轻量级树形插件</title><metacharset="utf-8"><linkrel="stylesheet"href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.2.1/themes/def......
  • 大屏自适应/适配方案【详解】(echarts自适配、rem、flexible.js、vscode中px2rem插件自
    原文链接:https://blog.csdn.net/weixin_41192489/article/details/120004315大屏自适应的核心目标有:字体大小随屏幕尺寸自适应变化详见下文自动撑满全屏设置如下.bg{background:url("~@/assets/images/主背景.png");position:fixed;top:0;left:0;wi......