1

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!

1
  • 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/… Commented Aug 6, 2014 at 18:25

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.