0

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!

Aziz
  • 1,584
  • 4
  • 23
  • 43
  • Javascrpt can't read your visitors files. If it could, nobody would surf any site with javascript on. – Jani Hyytiäinen Feb 03 '13 at 22:26
  • That is not correct. As you can see, I posted that this is a phonegap application (in the tags), and this allows you to read from the phone's memory. – Aziz Feb 04 '13 at 02:35

2 Answers2

3

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.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
1

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.

heads5150
  • 7,263
  • 3
  • 26
  • 34