开发者社区> 问答> 正文

如何post直传?

用post传递,。不是用包装好的sdk转的,也就是直接调用input(h5)控件,编译后的base64上传。


或者如何直接传文字,比如自定义数据。


我试一下,400   不知道怎么做,。有教程的链接么,我没找到这个教程。
$("#pz").change(function(){
                console.log(this.files[0]);
                var reader = new FileReader();
                reader.readAsDataURL(this.files[0]);
                reader.onload = function(e){
                    console.log ( this.result);
                    document.getElementById("headImg").src=this.result;
                }
            




    var glo_image_data = {
                OSSAccessKeyId:'qE3cx9cxglkZZH9V',
                accessKeySecret: 'BBmsLBUTHSHhBMk4RHzqKr7SQPdVif',
                policy:'',
                // signature:'',
                success_action_status:'201',
                key:'img/8.txt'
            },
            glo_image_upload_url = 'http://0123cf.oss-cn-hongkong.aliyuncs.com';
            
    function doUploadImage(url,data){
            var oMyForm = new FormData();
            console.log(oMyForm)
            for(var field_name in data){
                oMyForm.append(field_name,data[field_name]);
            }


            oMyForm.append("file", document.getElementById('pz').files[0]);


            var oReq = new XMLHttpRequest();
            //上传进度监听
            oReq.upload.onprogress = function (e) {
                if(e.type=='progress'){
                    var percent = Math.round(e.loaded/e.total*100,2)+'%';
                    console.log(percent);
                }
            };
            //上传结果
            oReq.onreadystatechange = function(e){
                if(oReq.readyState == 4){
                    if(oReq.status==201)//这里如果成功返回的是 success_action_status设置的值
                        alert('成功');
                    else
                        alert('失败');
                }
            };
            oReq.open("POST", url);
            oReq.send(oMyForm);
            // oReq.send("00");
    }
    doUploadImage(glo_image_upload_url,glo_image_data);


});







展开
收起
qiunuo 2016-08-31 09:29:41 3487 0
1 条回答
写回答
取消 提交回答
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载