Reading files in binary format
Hello All!
I'm trying to write a plugin that would allow sending files in pdf, midi formats to our webservice for further publication.
The following scenario is implemented:
- the user creates a composition (score),
- runs the plugin,
- the plugin exports the score to pdf and midi files on local disk,
- read and sends them to our web service.
I found the following problem: pdf files need to be read in binary format, FileIO component decodes non-ASCII characters when reading. I tried to read binary files using XMLHttpRequest, but in this case there is a distortion.
Please advise how I can solve this problem?
I use MuseScore version (64-bit): 3.2.3.7635 for Windows
Thank you.
Comments
Such a plugin for exporting exists already: https://musescore.org/en/project/batch-convert
In reply to Such a plugin for exporting… by Jojo-Schmitz
Thanks for the reply.
My problem is not writing (export) to pdf, but reading the pdf file into a variable for further sending via XMLHttpRequest. When reading via FileIO.read() distortion of non-ASCII characters occurs, I can't read the pdf file correctly without any loss.
In reply to Thanks for the reply. My… by NVoronkov
https://doc.qt.io/qt-5/qiodevice.html ? FileIO is MuseScore own method IIRC, not Qt's, it uses QFile.open() and indeed treats them as a text stream
In reply to https://doc.qt.io/qt-5… by Jojo-Schmitz
Сan you give a small example of the code or give a link to it, how can I use QT objects and methods in the
Musescore plugin (QML)?
Perhaps this library is connected through "import", then please tell me its name and version.
In reply to Сan you give a small… by NVoronkov
You'd need to check the Qt docs, one link to it above. Maybe using JavaScript to do the file handling?
In reply to You'd need to check the Qt… by Jojo-Schmitz
All I have is a Musescore "Plugin Creator", I can only create plugins in QML, to access the QIODevice Class I have to write something like this:
import QIODevice [version]
if so, please let me know the version of the library.
In reply to All I have is a Musescore … by NVoronkov
No idea about the version, and no idea where this might be documented (and whether it available to QML in the first place), so you may need to resort to trial and error there.
In reply to You'd need to check the Qt… by Jojo-Schmitz
I tried for JavaScript:
var reader = new FileReader();
The result:
ReferenceError: FileReader is not defined
Warning: :219: ReferenceError: FileReader is not defined
In reply to I tried for JavaScript: var… by NVoronkov
There's some documentation on the Qt site about integrating JavaScript code
The Qt File interface is only exposed through MuseScores FileIO object and handles text streams only.
But since you're using XMLHttpRequest anyway, you could use that instead. In QML there is no same-origin policy, meaning it can be used to read files from your local disk.
See attached example where the following file is being read in:
As you'll notice from the logging, the data doesn't stop after a 0 byte when using the ArrayBuffer response type.
Don't forget to remove the .qml extention from the readme.bin file; I've added it to be able to upload and attach it to this post.
In reply to The Qt File interface is… by jeetee
Thanks jeetee very much!
It works. I tried using XMLHttpRequest, but the devil is in the details. I watched "responseText" and I didn't know about responseType = "arraybuffer"