You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
there are no sync version of fs.openAsBlob (aka: fs.openAsBlobSync)
they are a Blob instead of Files and therefore lacks a file name and lastModified. So upgrading them to a File requires figuring out more stuff yourself.
What is the feature you are proposing to solve the problem?
and there is no way of getting around it cuz the async openAsBlob is the only thing you can work with. which makes your own code having to be async as well.
The fs.openAsBlob should be moved to Promises API and fs.openAsBlobSync should exist indeed. Drafted #49759 to address this.
const name = path.basename(filePath)
const stat = fs.statSync(filePath)
const blob = await fs.openAsBlob(filePath)
const file = new File([blob], name, {
- type: blob.type, // this is always empty string+ type: userProvidedMimeType,
lastModified: Number(stat.mtime)
})
This makes me wonder, wouldn't it be inconsistent that we set lastModified automatically but don't do that with type (using extension-mime map or libmagic)? Because the guessing should probably be done in userland. type property is read-only; so user wouldn't be able to set it after reading returned File, and fs.readAsFile(path, { type }) would work only if they know type beforehand.
I would not mind if it was able to guess the correct type.
I think the mimesniff spec is being used on many web related things... such as whatwg/fs and <input type="file"> are able to figure out some common types when getting access to a File
But i think we could focus on that later, it dose not really affect this issue directly.
i would say that is a blocker if NodeJS dose not have a built in mime sniffer.
(just created: #49843)
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
Activity
LiviaMedeiros commentedon Sep 22, 2023
The
fs.openAsBlobshould be moved to Promises API andfs.openAsBlobSyncshould exist indeed. Drafted #49759 to address this.const name = path.basename(filePath) const stat = fs.statSync(filePath) const blob = await fs.openAsBlob(filePath) const file = new File([blob], name, { - type: blob.type, // this is always empty string + type: userProvidedMimeType, lastModified: Number(stat.mtime) })This makes me wonder, wouldn't it be inconsistent that we set
lastModifiedautomatically but don't do that withtype(using extension-mime map or libmagic)? Because the guessing should probably be done in userland.typeproperty is read-only; so user wouldn't be able to set it after reading returnedFile, andfs.readAsFile(path, { type })would work only if they know type beforehand.jimmywarting commentedon Sep 23, 2023
Don't mind that
👍
I would not mind if it was able to guess the correct type.
I think the mimesniff spec is being used on many web related things... such as
whatwg/fsand<input type="file">are able to figure out some common types when getting access to aFileBut i think we could focus on that later, it dose not really affect this issue directly.
i would say that is a blocker if NodeJS dose not have a built in mime sniffer.
(just created: #49843)
github-actions commentedon Mar 23, 2024
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.
For more information on how the project manages feature requests, please consult the feature request management document.
github-actions commentedon Apr 22, 2024
There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.
For more information on how the project manages feature requests, please consult the feature request management document.