在MVC中上传文件时,字符串或二进制数据将被截断 [英] String or binary data would be truncated when uploading file in MVC
问题描述
文件只有14kb(14,000字节).我已经读到varbinary(max)
列类型(这是我正在使用的)仅支持8,000个字节.那是对的吗?如何将文件上传到数据库?
The file is only 14kb (14,000 bytes). I have read that the varbinary(max)
column type (which is what I am using) only supports 8,000 bytes. Is that correct? How can I upload my file into the database?
if (file.ContentLength < (3 * 1048576))
{
// extract only the fielname
var fileName = Path.GetFileName(file.FileName);
using (MemoryStream ms = new MemoryStream())
{
file.InputStream.CopyTo(ms);
byte[] array = ms.GetBuffer();
adj.resumeFile = array;
adj.resumeFileContentType = file.ContentType;
}
}
错误:
字符串或二进制数据将被截断.该声明已经 终止.
String or binary data would be truncated. The statement has been terminated.
推荐答案
检查在此过程中要插入的其他列.我将特别检查ContentType
列,因为这将类似于image/jpeg
,而不仅仅是image或jpeg.
Check your other columns that you are inserting into during this process. I would especially check the ContentType
column as this will be something like image/jpeg
and not simply image or jpeg.
这是一个可能的内容类型列表,以便您可以在ContentType中创建足够的空间列.
Here is a list of possible content types so that you can create enough space in your ContentType column accordingly.
这篇关于在MVC中上传文件时,字符串或二进制数据将被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!