Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

read from blob not working #971

Closed
SamanthaAdrichem opened this issue Jan 23, 2018 · 4 comments
Closed

read from blob not working #971

SamanthaAdrichem opened this issue Jan 23, 2018 · 4 comments

Comments

@SamanthaAdrichem
Copy link
Contributor

SamanthaAdrichem commented Jan 23, 2018

AlaSQL is based on unpaid voluntary work. Thank you for taking the time to make it better.

Something not working as expected?
we're using https://github.com/danialfarid/ng-file-upload for uploading files resulting in a File Object
(https://developer.mozilla.org/nl/docs/Web/API/File)
So basically you would expect that i could read it from a blob using the following code:

alasql.promise('select * from CSV(?)', file).then( function() { console.log( arguments ) }, function() { console.log( arguments ) } );
or this code
alasql.promise('select * from CSV(?)', [file]).then( function() { console.log( arguments ) }, function() { console.log( arguments ) } );

it however does nothing, no errors, no promise resolved nothing.

I'm expecting atleast an error :(

I just downloaded the latest zip from here. We're loading these two files:

alasql/dist/alasql.min.js
alasql/console/xlsx.core.min.js

@SamanthaAdrichem
Copy link
Contributor Author

for csv's i can do something like:

let reader = new FileReader();
let csvContents = "";

reader.addEventListener('loadend', (e) => {
 csvContents+= e.srcElement.result;
});

alasql.promise('select * from CSV(?)', csvContents);

and thus read from string. I'd prefer a blob though. So that the syntax with XLSX is the same

With XLSX i get the following error if i add the blob.

TypeError: Cannot read property 'uint8array' of undefined
at Object.exports.transformTo (eval at module.exports (webpack-internal:///110), :2:31270)
at ZipEntries.prepareReader (eval at module.exports (webpack-internal:///110), :3:4593)
at ZipEntries.load (eval at module.exports (webpack-internal:///110), :3:4652)
at new ZipEntries (eval at module.exports (webpack-internal:///110), :3:851)
at JSZip.module.exports [as load] (eval at module.exports (webpack-internal:///110), :2:9664)
at new JSZip (eval at module.exports (webpack-internal:///110), :2:8756)
at Object.readSync [as read] (eval at module.exports (webpack-internal:///110), :9:7407)
at eval (eval at module.exports (webpack-internal:///110), :2:18112)
at Object.C.loadBinaryFile (eval at module.exports (webpack-internal:///110), :11:9131)
at S (eval at module.exports (webpack-internal:///110), :2:17993)
at Object.A.from.XLSX (eval at module.exports (webpack-internal:///110), :15:23722)
at Object.eval [as datafn] (eval at (eval at module.exports (webpack-internal:///110)), :3:28)
at eval (eval at module.exports (webpack-internal:///110), :2:6973)
at Array.forEach ()
at o (eval at module.exports (webpack-internal:///110), :2:6933)
at s (eval at module.exports (webpack-internal:///110), :12:8415)
at Function.A.dexec (eval at module.exports (webpack-internal:///110), :11:16550)
at Function.A.exec (eval at module.exports (webpack-internal:///110), :11:15985)
at A (eval at module.exports (webpack-internal:///110), :2:20394)
at eval (eval at module.exports (webpack-internal:///110), :11:24088)
at new ZoneAwarePromise (webpack-internal:///485:890:29)
at j (eval at module.exports (webpack-internal:///110), :11:24053)
at Function.A.promise (eval at module.exports (webpack-internal:///110), :11:24596)
at parseFile (webpack-internal:///2050:82:11)
at eval (webpack-internal:///2050:63:5)
at Object.forEach (webpack-internal:///487:408:20)
at AdminFinanceSovendusExportConverterController.processFiles (webpack-internal:///2050:62:12)
at fn (eval at compile (webpack-internal:///487), :4:260)
at update (webpack-internal:///1643:967:27)
at eval (webpack-internal:///1643:1033:11)
at eval (webpack-internal:///487:20545:31)
at completeOutstandingRequest (webpack-internal:///487:6419:10)
at eval (webpack-internal:///487:6699:7)
at ZoneDelegate.invokeTask (webpack-internal:///485:425:31)
at Zone.runTask (webpack-internal:///485:192:47)
at ZoneTask.invokeTask (webpack-internal:///485:499:34)
at ZoneTask.invoke (webpack-internal:///485:488:48)
at timer (webpack-internal:///485:2040:29)

The XLSX itself is a simple created xlsx in microsoft excell containing two rows

a, b, c
1, 2, 3

@mathiasrw
Copy link
Member

Creat bug report. Lets solve this together. Ill have a look next time I have 30 mins free.

@SamanthaAdrichem
Copy link
Contributor Author

I've found this issue online: open-xml-templating/docxtemplater#102
basically stating, maybe that has something to do with the XLSX issue

"The issue was the .docx file was not in the same folder as the HTML page."

though it's a blob in memory

@SamanthaAdrichem
Copy link
Contributor Author

SamanthaAdrichem commented Jan 24, 2018

I've created a work-around which is quite simple and according to caniuse.com browser compatible
enough. I would just add this to your documentation as the solution.

let fileAsObjectUrl = URL.createObjectURL( file );
alasql.promise('select * from xlsx(?, {autoExt: false})', [fileAsObjectUrl])
    .then( function() { console.log( arguments ) }, function() { console.log( arguments ) } );

where xlsx can also be changed to csv and it also works for csv's

This creates a physical file in the local browser cache. The file however does not contain an extension, and you need to disable the autoExt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants