仅在单击提交按钮时将jQuery上传到Cloudinary

时间:2018-09-18 02:42:07

标签: jquery django

我对将图像直接上传到 Cloudinary 有疑问。

选择文件后,它开始上传。我不喜欢这种方法,我希望单击 submit 按钮后立即开始上传。

//HTML
<div class="clearfix margin-top-10">
<pre class="label label-danger">NOTE! </pre>  
<span>Please upload only one picture of the missing person </span>
<pre class="status"></pre>
<div class="preview"></div>
<input type="hidden" name="image" id="recent_image" value="">
</div>
<div class="margin-top-10">
<a class="btn green-haze" id="submit">Submit </a>
<a href="javascript:;" class="btn default pull-right">Cancel </a>
</div>

//Javascript
$(document).ready(function() {
$("#id_image").removeAttr("required");
    $("#submit").on("click",function(){
        console.log("working")
            if($.fn.cloudinary_fileupload !== undefined) {
                $(".cloudinary-fileupload").cloudinary_fileupload({
                    replaceFileInput: false,
                    autoUpload: false,
                  });
                }

                  cldFU.bind('fileuploadadd', function (e, data) {
                      console.log('Uploading');
                    data.submit();
                  })

                  cldFU.off("cloudinarydone").on("cloudinarydone", function (e, data) {
                    $("#photo_bytes").val(data.result.bytes);
                    $("#recent_image").val(data.result.url);
                  })
                  cldFU.bind('cloudinarydone', function(e, data) {
                    console.log(data);

                    return true;
               });
            });
        });

0 个答案:

没有答案