0

I have a form where users are able to upload images to the website. The images are stored in binary, in the table.

I use ajax and JQuery on the site and it is never reloaded so when a users enter the data and push submit, the page is not reloaded. Instead I use ajax to upload the the data to the server.

When I just passthrough text it looks like this:

$("#storeDataAndImgBtn").bind("click", function () {
    var msg = $("#emailMsg").val();
    var from = $("#fromEmail").val();
    $.ajax({
        type: "POST",
        url: "Default.aspx/storeDataAndImg",
        data: "{\"from\":\"" + from + "\" ,\"msg\":\"" + msg + "\" ,\"value\":\" 'image should be here' \" }",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (temp) {
            alert(temp.d);
            $("#mailForm").fadeOut(function () {
                $("#overlay").fadeOut();
            });
        }
    });
    return false;
});

My question is how i can passthrough the image so that I can store it in the database?

2 Answers 2

1

I am assuming that the image is just a Input Type="File". If this is the case, you cannot access the Input field using Ajax due to security reasons. I believe the best solution is using an IFrame for the submit target. It's not pretty but it works.

SOF - How to make Asynchronous(AJAX) File Upload using iframe

Your other option is to use a Flash/Silverlight/etc plugin to. I am currently using SWFUpload.

SWFUpload

Sign up to request clarification or add additional context in comments.

Comments

0

If possible, I would suggest not storing the image in the database. Instead, store images on the server's file-system.

Refer here for similar/related questions: store image in database or in a system file?

2 Comments

Okay, so say that I actually change so that I store the images onto the server's file-system instead. How do I (without reloading the page, making a post) store the image onto the file-system?
Hmm, using Ajax this doesn't really happen out of the box; but you may find what you need here: geekswithblogs.net/rashid/archive/2007/08/01/… and also a similar question/answer here: stackoverflow.com/questions/254831/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.