简体   繁体   English

将mp3文件发送到MVC3应用并存储在sql server中

[英]Send mp3 file to MVC3 app and store in sql server

I have a PhoneGap application that contains mp3 files, I have their path in a variable -- uses JS 我有一个包含mp3文件的PhoneGap应用程序,我在一个变量中有它们的路径-使用JS

Back End is an MVC3 app with SQL server using c# 后端是使用c#的带有SQL Server的MVC3应用


My question is how do I send a file from my app using javascript to the back end and then store it in the sql server? 我的问题是如何使用JavaScript将应用程序中的文件发送到后端,然后将其存储在sql服务器中?

I am very new to using js and I would greatly appreciate some guidance! 我对使用JS非常陌生,非常感谢您提供一些指导!

You could use standard HTML form to upload a file on your server. 您可以使用标准HTML表单在服务器上上传文件。 I have recently answered a similar question about uploading a file in ASP.NET MVC. 我最近answered a similar question有关在ASP.NET MVC中上传文件answered a similar question

If you want to use javascript on the client you could take a look at some of the javascript file upload plugins that exists such as Uploadify and Fine Uploader . 如果要在客户端上使用javascript,则可以查看一些存在的javascript文件上传插件,例如UploadifyFine Uploader They allow you to provide additional user experience such as displaying upload file progress for example. 它们使您能够提供额外的用户体验,例如显示上传文件的进度。

As far as storing the uploaded file to SQL server is concerned, you could have a varbinary(max) or FILESTREAM column in your database in which you could store the uploaded file bits. 就将上载的文件存储到SQL Server而言,您的数据库中可以有一个varbinary(max)FILESTREAM列,您可以在其中存储上载的文件位。 Querying a relational database could be achieved with either plain old ADO.NET or using an ORM framework such as Entity Framework for example. 查询关系数据库可以使用普通的旧ADO.NET或使用ORM框架(例如Entity Framework来实现。

If you want to use javascript on the client you could take a look at some of the javascript file upload plugins available through Google. 如果您想在客户端上使用javascript,则可以查看通过Google提供的一些javascript文件上传插件。

As for storing in the database you can store the MP3 data itself in a varbinary(max) or FILESTREAM field. 至于存储在数据库中,您可以将MP3数据本身存储在varbinary(max)或FILESTREAM字段中。

Personally I wouldn't I would store it on the file system and put the path into a varchar field. 就我个人而言,我不会将其存储在文件系统中并将路径放入varchar字段中。 By doing this it avoids the added overhead of fetching all the data via the database server. 通过这样做,避免了通过数据库服务器获取所有数据的额外开销。 Then the code can just use normal file IO methods. 然后,代码可以只使用常规文件IO方法。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM