473,396 Members | 1,768 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Save images in SQL DB via MVC2

1
When I run my website it shows the following error:
"The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters."
My View code:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Title="register" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<blog.models.users>" %>
  2. <%@ Import Namespace="blog.Models" %>
  3.  <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
  4. <%using(Html.BeginForm("register","users",FormMethod.Post,new{enctype="multipart/form-data"}))
  5. {%>  <br />
  6. <input type="file" name="upic"/>
  7. <input type="submit" value="upload"/>
  8. <%}%>
  9.  
  10. </asp:Content>

I use linq to SQL,not Entity Framework ,the controller code is:

Expand|Select|Wrap|Line Numbers
  1. [AcceptVerbs(HttpVerbs.Post)]
  2.       public ActionResult register([Bind(Exclude = "file")]HttpPostedFileBase file, users u)
  3.       {
  4.               var v = db.users;
  5.               var sna = Request.Form["name"];
  6.  
  7.               if (v.Count(d => d.name == sna) > 0)
  8.               {
  9.  
  10.                ckn = 0;
  11.  
  12.               }
  13.  
  14.               if (ckn == 1 && sna !="")
  15.               {
  16.                   //如果没错误,返回首页
  17.  
  18.                   u.uid = SqlHelper.get_ID("users", "uid");
  19.                   u.rdate = DateTime.Now;
  20.                   u.ndate = DateTime.Now;
  21.                   u.pwd = SqlHelper.md5(u.pwd);
  22.                   u.jib = 2;
  23.                   u.psum = 0;
  24.                   file = Request.Files["upic"];
  25.                     Int32 len = file.ContentLength;
  26.  
  27.                  u.pict = file.ContentType;
  28.  
  29.  
  30.                  byte[] photo = new byte[len];
  31.  
  32.                  file.InputStream.Read(photo, 0, len);
  33.  
  34.                  u.upic = photo;
  35.  
  36.  
  37.  
  38.  
  39.                   db.SubmitChanges();
  40.  
  41.                   db.users.InsertOnSubmit(u);
  42.                   db.SubmitChanges();
  43.               }
  44. }

What makes the error occur
And how do you resolve this problem?

Thanks for helping me!
Mar 18 '12 #1
0 1769

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: lir | last post by:
Hi, I am trying to save a fram in a page using the execCommand("saveas") the html is save currectly but I can not save the gif on that page. How can I save the fram with the gif via...
1
by: mohan21_kumar | last post by:
Hi, How to Save images in ms word file when it is downloaded from asp.net application. I have used the following code to convert the html page into ms word file. but i'm not able to save the...
8
by: Mario Krsnic | last post by:
Hello and Merry Christmas! I flip in my card play some cards using the call "drawimage". These flipped cards are saved in temporary images on the server: temp1.jpg, temp2.jpg... Everything works...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
I'm having the wierdest problem. I'm trying to save images into a SQL 2005 database. the field is just called "IMAGES" and hte data type is "image". here is my code to save //following code...
3
by: jayasabari | last post by:
hai, i am saving the image in server by using response.saveas("path name") in .net. The image is saving but preview is not available. please can you give any suggestion. With Regards,...
4
by: Logician | last post by:
I am running on my PC Windows Forms to collect data from websites, including images. I hit a problem with images and javascript, and I would appreciate any help. The current code fails with a...
2
by: Simon Wigzell | last post by:
I have inherited a database driven website that comes with a table of image links. The images are scattered all of the internet and there are thousands of them. I would like to write an asp script...
4
by: yosh29rs | last post by:
I really have difficulty trying to save images to my vb program. Can anybody please help me how to save images in a simple vb program?
1
by: saadkhan | last post by:
please help me that how could i be able to save images in an array. I have made an array like: System.Drawing.Image arr = new System.Drawing.Image; But i have no idea how to save different images...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.