简体   繁体   English

从JavaScript客户端向SQL Server发送图像的最佳格式

[英]Best format to send image from javascript client to SQL server

I am making an application that will store a Azure SQL server DB user information, including profile photo downloaded from Facebook. 我正在制作一个应用程序,该应用程序将存储Azure SQL Server数据库用户信息,包括从Facebook下载的个人资料照片。 On the server side, ASP.NET MVC4'll have a controller that will receive the information and send it to the database. 在服务器端,ASP.NET MVC4将具有一个控制器,该控制器将接收信息并将其发送到数据库。

The client side is Javascript and thought to give the image in json (once converted to base64). 客户端是Javascript,被认为可以将图片提供给json(一旦转换为base64)。 Is it a good option? 这是一个好选择吗? Is it better to directly send the jpg? 直接发送jpg更好吗? What are the advantages of sending information in json? 在json中发送信息有什么优势?

In SQL Server image field would be stored as a nvarchar (max) 在SQL Server中,图像字段将存储为nvarchar(最大值)

Are you going to return the image as a binary stream content type image/jpeg or as a text stream encoded base64? 您要以二进制流内容类型image/jpeg还是以文本流编码的base64返回图像? Is far more likely that you're going to do the former, so there is little reason to go through an intermediate base64 encoded transfer. 您很可能会采用前者,因此没有必要进行中间的base64编码传输。 And of course, store them as VARBINARY(MAX) . 当然,将它们存储为VARBINARY(MAX) Even if you would choose to store them as base64, choosing an Unicode data type for base64 text is really wasteful, (double the storage cost for no reason...), base64 can fit very well in VARCHAR(max) . 即使你会选择将它们存储为base64,选择最适合的base64文本的Unicode数据类型实在是浪费,(双无故...存储成本)的base64可以适应得很好VARCHAR(max)

But, specially in a SQL Azure environemnt, you should consider storing media in Azure BLOB storage and store only the Blob path in your database. 但是,特别是在SQL Azure环境中,您应该考虑将媒体存储在Azure BLOB存储中,并且仅将Blob路径存储在数据库中。

In my opinion, it's better sending the image directly in .jpg using Multipart Forms or something like that. 在我看来,最好使用Multipart Forms或类似的方式直接将图像发送为.jpg。

Sending information in Json is useful when you transfer explicit data, like collections or objects that you will be able to query or de-serialize later. 当您传输显式数据(例如可以稍后查询或反序列化的集合或对象)时,使用Json发送信息非常有用。

The client side is Javascript and thought to give the image in json (once converted to base64). 客户端是Javascript,被认为可以将图片提供给json(一旦转换为base64)。 Is it a good option? 这是一个好选择吗?

As Pasrus pointed out, you are not going to manipulate the image data. 正如Pasrus指出的那样,您不会操纵图像数据。 So JSON does not seems to be a good choice here. 因此,JSON在这里似乎不是一个好选择。

One option is, you can add the base64 data into src attribute in html tag and send it. 一种选择是,您可以将base64数据添加到html标记的src属性中并发送。

What are the advantages of sending information in json? 在json中发送信息有什么优势?

Please check this answers and there are so many: 请检查此答案,并且有很多:

Advantages of using application/json over text/plain? 使用application / json优于text / plain的优势?

In SQL Server image field would be stored as a nvarchar (max) 在SQL Server中,图像字段将存储为nvarchar(最大值)

Please refer this link: 请参考以下链接:

Storing images in SQL Server? 在SQL Server中存储图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用REST API将图像从服务器发送到客户端 - send image from server to client with REST API 从输入获取图像并将其发送到服务器JavaScript React App的最佳方法 - Best Way to take an image from input and send it to server JavaScript React App 从Microsoft SQL Server数据库向JavaScript函数发送数据的最佳方法 - The best way to send data to JavaScript functions from a Microsoft SQL Server Database 如何使用 Java / Javascript 通过 Web Socket 将图像从服务器发送到客户端? - How to send an image from server to client with Web Socket using Java / Javascript? 将日期从客户端(Javascript)发送到WebApi的最佳方法是什么 - What is the best way to send Date from client(Javascript) to WebApi 使用 4G 将消息从 android 客户端发送到服务器的最佳方式? - Best way to send message from android client to server with 4G? 将画布图像发送到服务器格式JPG javascript或jquery - send a canvas image to server format JPG javascript or jquery 将图像从websocket服务器.NET发送到客户端(HTML5) - send image from websocket server .NET to client (HTML5) 如何将图像从桌面(客户端)发送到服务器,反之亦然 - How to send an image from desktop(client) to server & vice versa 将捕获的图像从python服务器发送到javascript客户端 - Send captured images from python server to javascript client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM