Use JavaScript to turn a picture into a base64 bit encoding and then transfer it to the server (the interface of the AJAX call is based on DRUPA7)

Source: Internet
Author: User

<! DOCTYPE html>//base64 transcoding function        functionBase64 (file, callback) {varCoolfile = {}; functionReaderonload (e) {varBase64 =Btoa (E.target.result); Coolfile.base64=base64;            Callback (Coolfile)}; varReader =NewFileReader (); Reader.onload=Readeronload; varFile = File[0].files[0]; Coolfile.filetype=File.type; Coolfile.size=file.size; Coolfile.filename=File.name;        reader.readasbinarystring (file); }        functionAA () {//var preview = document.queryselector (' img ');            //var file = document.queryselector (' #files '). Files[0];            varName = $ (' #files '). Val (); Base64 ($ (' Input[type= ' (file "] '),function(data) {//Console.log (data.base64)              vardata = {                  "File":{                      "File":d ata.base64,"FileName": Name,"FilePath": "public://" +name}}; Options={type:"POST", Data:data, url:"Http://demo.dd:8083/userapi/app_services/UploadFile", DataType:' JSON ', Success:function(Result) {Console.log (json.stringify (result));              }              };          $.ajax (options); })        }    </script>

Use JavaScript to turn a picture into a base64 bit encoding and then transfer it to the server (the interface of the AJAX call is based on DRUPA7)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.