I have a PhoneGap application that contains mp3 files, I have their path in a variable -- uses JS
Back End is an MVC3 app with SQL server using c#
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?
I am very new to using js and I would greatly appreciate some guidance!
You could use standard HTML form to upload a file on your server. I have recently answered a similar question
about uploading a file in ASP.NET MVC.
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
. 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. Querying a relational database could be achieved with either plain old ADO.NET
or using an ORM framework such as Entity Framework
for example.
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.
As for storing in the database you can store the MP3 data itself in a varbinary(max) or FILESTREAM field.
Personally I wouldn't I would store it on the file system and put the path into a varchar field. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.