首页 > 解决方案 > 如何将上传的图像转换为字节数组javascript

问题描述

i want to upload images to the server using ajax post request , here my question was how to convert image to a byte array for sending image to the server as multipart how can i achieve this.


here I posted what I tried:

<div class="col-sm-6 col-md-4 form-group">
                            <label>Attachement</label>
                            <input id="other_fileUpload_create" type="file" class="form-pcontrol">
                        </div>

阿贾克斯:

  var formData = new FormData();
        $.ajax({
            url: baseURL + '/misportal/ptwRest/saveIsolation',
            type: "POST",
            contentType: false,
            processData: false,
            data: function() {

              //  var inputs = $('#IsolationFO').serializeArray();

 //here i got image path instead of byte array  

             formData.append("Image",$('#other_fileUpload_create').val());


                return formData;
            }(),

标签: javascriptajaxmultipart

解决方案


推荐阅读