Character encoding information is lost when saving a data URI
hubgit opened this issue · comments
Steps to reproduce
- Tell us what broke. The more detailed the better.
A UTF-8 encoded HTML string saved as to the blob store will be retrieved with no encoding specified, leading to garbled characters.
- If you can, please create a simple example that reproduces the issue
const div = '<p>don’t</p>'
// convert the HTML string to a Buffer
const buffer = Buffer.from(html)
// convert the Buffer to a Base64-encoded data URI
const uri = dauria.getBase64DataURI(buffer, 'text/html;charset=utf-8')
console.log(uri.substr(0, uri.indexOf(',')))
// data:text/html;charset=utf-8;base64
// store the HTML blob
const saved = await app.service('blobs').create({ uri })
// load the HTML blob
const blob = await app.service('blobs').get(saved.id)
console.log(blob.uri.substr(0, blob.uri.indexOf(',')))
// data:text/html;base64
Expected behavior
The charset
information should be preserved.
Actual behavior
The charset
information is lost. This is because only the part of the data URI after the prefix is stored, then on retrieval the extension of the blob's filename is used to guess what the "content-type" part of the prefix should be.
System configuration
Tell us about the applicable parts of your setup.
feathers-blob v1.2.0
One solution might be to store the whole data URI in the file, instead of decoding it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Apologies if the issue could not be resolved. FeathersJS ecosystem modules are community maintained so there may be a chance that there isn't anybody available to address the issue at the moment. For other ways to get help see here.