Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

44
Views
Pass file through ajax with nodejs
    const editProductBody = document.querySelector('#update-product-modal .modal-body')
    $.get({
        url: '/admin/product/detail/' + productId,
        contentType: 'multipart/form-data',
        success: function(response) {
            editProductBody.innerHTML = `
                <form action="/admin/product/update/${response._id}?_method=PUT" method="POST">
                    <label for="">Product name<span style="color: red;">*</span></label> <br>
                    <input type="text" name="name" value="${response.name}"><br>
                    <label for="">Price<span style="color: red;">*</span></label> <br>
                    <input type="text" name="price" value="${response.price}"><br>

                    <label for="">Pictures<span style="color: red;">*</span></label> <br>
                    <div class="row">
                        <div class="col-sm-9 ml-auto">
                            <img src="${response.photo[0]}"> <br>
                            <img src="${response.photo[1]}"> <br>
                        </div>
                        <div class="col-sm-3 ml-auto"> 
                            <input type="file" class="form-control" name="image1" id="image1">
                            <input type="file" class="form-control" name="image2" id="image2">
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                        <button id="btn-update-product" class="btn btn-primary">Update</button>
                    </div>
                </form>`
        }
    })

When I req.body, it has image1, image2 but I want to transfer them as files to process with cloudinary. How can I fix it ?

7 months ago ยท Juan Pablo Isaza
Answer question
Find remote jobs