Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm getting the URL to a sqlite db file on my server from the browser url using query string.

So in the app I have the file url.

Then I'm calling an angular $http.get function on that url.

This gives me the data in the file, but the library I'm using to read the data requires a file object.

Is there a way to create a file object from the paramiters inside $http.get? The parameters are data, status, headers, and config, I also have the file name.

I've tried constructing a blob but I keep getting an error saying "the database disk image is malformed." Here is the blob construction Inside the $http.get function:

            ...
            var blob = [];
            var blob2 = {fileName:null};
            $http.get(fileName).
              success(function (data, status, headers, config) {
                blob[0] = data;

                var theBlob = new Blob(blob, {name:fileName},{status:status},{headers:headers},{config:config}, {type : ''});
                var r = new FileReader();
                r.onload = function () {                    
                    var Uints = new Uint8Array(r.result);
                    db = new SQL.Database(Uints); 
                ...

I've also tried building the blob by adding the $http.get data, status, headers, and config parts as more parts of the blob[] array, and passing that to the new Blob constructor...

Any help would be really appreciated, thanks!

share|improve this question
    
I'm basically trying to mimic the html input type=file functionality, but with the file name coming from the URLs query string, not an input tag. Here is a stackoverflow question where the developer gave up and said it wasn't possible, but there isn't any confirmation from the community: stackoverflow.com/questions/15037729/… –  Chris Ubick Aug 6 '14 at 18:25

1 Answer 1

up vote 0 down vote accepted

I ended up using a button and assigning a load from url event to it, this way I didn't have to build my own blob. When i built my own blob, sql.js was unable to parse my sqlite db file. It seemed as if the headers were missing, but I couldn't get them added in a way that sql.js would read correctly.

With a modified use case, the load from url button option works fine. I even have the button hidden unless there is data returning from the query string in the url. This means the button to load from url only shows up when the url has a query string in it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.