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.
我在网站上使用ajax和JQuery,它永远不会重新加载,因此当用户输入数据并推送提交时,页面不会重新加载。相反,我使用ajax将数据上传到服务器。
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 个解决方案
#1
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.
我假设图像只是一个输入类型=“文件”。如果是这种情况,由于安全原因,您无法使用Ajax访问Input字段。我认为最好的解决方案是使用IFrame作为提交目标。它不漂亮,但它的工作原理。
SOF - How to make Asynchronous(AJAX) File Upload using iframe
SOF - 如何使用iframe进行异步(AJAX)文件上载
Your other option is to use a Flash/Silverlight/etc plugin to. I am currently using SWFUpload.
您的另一个选择是使用Flash / Silverlight / etc插件。我目前正在使用SWFUpload。
SWFUpload的
#2
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?
有关类似/相关问题,请参阅此处:将图像存储在数据库或系统文件中?
#1
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.
我假设图像只是一个输入类型=“文件”。如果是这种情况,由于安全原因,您无法使用Ajax访问Input字段。我认为最好的解决方案是使用IFrame作为提交目标。它不漂亮,但它的工作原理。
SOF - How to make Asynchronous(AJAX) File Upload using iframe
SOF - 如何使用iframe进行异步(AJAX)文件上载
Your other option is to use a Flash/Silverlight/etc plugin to. I am currently using SWFUpload.
您的另一个选择是使用Flash / Silverlight / etc插件。我目前正在使用SWFUpload。
SWFUpload的
#2
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?
有关类似/相关问题,请参阅此处:将图像存储在数据库或系统文件中?