0

The photos come in a byte array. Sending an object list include byte array to controller with ajax.

As the quality of the photos increases, the byte array grows, which makes it a mistake. Not going to controller. However, when the quality of the photos is low, the operation is successful.

I think json gives error because size is big.

          $.ajax({
            type: "GET",
            url: photoApi,        
            crossDomain: true,
            dataType: "json",
            success: function (data) {
                $.each(data,
                    function (i, list) {                          

                        $.each(list,
                            function (i, ves) {
                                var Picture = new Uint8Array(ves.Picture)
                               // adding to list
                                photoObj["items"].push({ "Id": ves.Id, "Picture": btoa(String.fromCharCode.apply(null, Picture)), "User": ves.User, "CreatedDate": ves.CreatedDate });

                            }
                        );

                        $.ajax({
                            type: 'POST',
                            url: '/File/Photo',
                            data: JSON.stringify(photoObj),
                            contentType: "application/json; charset=utf-8",                               
                            success: function (data) {            

                                $("#divAttachments").html(data);
                            },
                            error: function (ex) {
                                //comes here when photo quality improves
                                alert('error' + ex);
                            }
                        });

                    });


            },
            error: function (request, status, error) {
                console.log(request);

            }
        });
Gunseli
  • 1
  • 1
  • I'm assuming, since you've tagged this asp.net-mvc, that the app is hosted on IIS (IISExpress, when debugging). There's a default maximum file size of around 4 MB which you can override: https://stackoverflow.com/questions/3853767/maximum-request-length-exceeded – Tieson T. Nov 26 '19 at 07:01
  • Thank you for your answer. But I have the following codes in web config. – Gunseli Nov 26 '19 at 07:10
  • Do you have any logging enabled? That will tell you what error, if any, is happening during the request. Also worth pointing out that Base-64 encoding _does_ have an overhead to be aware of: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#Encoded_size_increase – Tieson T. Nov 26 '19 at 07:21

0 Answers0