• 上传文档

      1. //js
      2. handleFile=(e)=>{
      3. let params=new FormData()
      4. params.append("file",e.target.files[0])
      5. this.$axios.post('/api/file/upload/25',params,{
      6. headers: {'Content-Type': 'multipart/form-data'}
      7. }).then(res=>{
      8. console.log(res)
      9. })
      10. }
      11. <div className='file-iptc'>
      12. <button>上传文档</button>
      13. <input onChange={this.handleFile} className='file-ipt' type='file'/>
      14. </div>
      1. //css
      2. .file {
      3. &-iptc {
      4. position: relative;
      5. overflow: hidden;
      6. }
      7. &-ipt {
      8. height:100%;
      9. position: absolute;
      10. left: 0;
      11. to: 0;
      12. opacity: 0;
      13. }
      14. }
    • 拍照上传

      1. //谷歌调取摄像头
      2. https://blog.csdn.net/qq_26975307/article/details/84560216
      1. https://www.jianshu.com/p/dca86d777c50
      2. //上传
      3. $('#upload').click(function(){
      4. let canvas = document.getElementById("canvas");
      5. $('#upload-group').hide();
      6. $('#loading').show();
      7. canvas.toBlob(function(blob) {
      8. blob.lastModifiedDate =new Date();
      9. blob.name = 'file.jpg';
      10. let formData = new FormData();
      11. formData.append('file', blob, "file.jpg");
      12. formData.append("csrfmiddlewaretoken", $('[name="csrfmiddlewaretoken"]').val());
      13. $.ajax({
      14. url: "/auth/face_match",
      15. type: "POST",
      16. data: formData,
      17. contentType: false,
      18. processData: false,
      19. mimeType: "multipart/form-data",
      20. dataType:'json',
      21. success: function (data, status) {
      22. if(!data['ok']){
      23. alert(data['message']);
      24. }else{
      25. if(data['data']['result']){
      26. location.href='/auth/me';
      27. }else{
      28. alert('头像认证失败');
      29. location.reload();
      30. }
      31. }
      32. },
      33. });
      34. },'image/jpeg',0.7);
      35. });