Java Web实现文件上传(相机、相册)

H5页面中通过JQuery的方式实现相机、相册、拍摄视频三种方式的文件上传,Java后端通过Servlet的方式来接收上传的文件并写入的服务端存储目录中。

前端HTML文件:
<div class="log" style="text-align: center;float: left;width: 65px;margin: 20px 5px 0px 30px;font-size: 13px;color: #333;" >
	<a id="postfile_camera" style="" class="file">
		<img src="img/img_cam.png" style="width: 65px;cursor: pointer;" for="file_camera" >
		<input type="file" name="file_camera" id="file_camera"  accept="image/*" capture="camera" style="opacity: 0;height: 85px;width: 65px;position: absolute;z-index: 11;top: 20px;left: 30px;">
		<span class="log_text" >拍照</span>
	</a>
</div>
<div class="log" style="text-align: center;float: left;width: 65px;margin: 20px 5px 0px 30px;font-size: 13px;color: #333;" >
	<a id="postfile_video" style="" class="file">
		<img src="img/video.png" style="width: 65px;cursor: pointer;" for="file_video" >
		<input type="file" name="file_video" id="file_video"  accept="video/*" capture="camcorder" style="opacity: 0;height: 85px;width: 65px;position: absolute;z-index: 11;top: 20px;left: 130px;">
		<span class="log_text" >录像</span>
	</a>
</div>
<div class="log" style="text-align: center;float: left;width: 65px;margin: 20px 5px 0px 30px;font-size: 13px;color: #333;" >
	<a id="postfile_" style="" class="file">
		<img src="img/img_pic.png" style="width: 65px;cursor: pointer;" for="file_pic">
		<input type="file" name="file_pic" id="file_pic" accept="image/*" style="opacity: 0;height: 85px;width: 65px;position: absolute;z-index: 11;top: 20px;left: 230px;">
		<span class="log_text" >相册</span  >
	</a>
</div>
前端JS文件,通过Ajax方式提交文件:
var send_file_num = 0//相机拍照上传
$('#file_camera').localResizeIMG({
   
	width: 800,
	quality: 1,
	success: function (result) {
   
		send_file_num ++;
		var num = send_file_num;
		sendImgFile(result, num);
		
		console.log(result);
	},
	before: function(thisObj, blob, file){
   
		console.log
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只造梦者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值