admin管理员组文章数量:1394526
I'm trying to upload images to the firebase storage. When I upload them to the storage, I see them with a type: application/octet-stream
instead of image/jpeg
or image/png
.
This is the code I use:
<input
type="file"
id="img"
name="filename"
accept="image/*"
onChange={(e) => {
handleChange(e);
}}
/>
const handleChange = async (e) => {
const imgRef = await firebase.storage().ref('images/' + image.name);
await imgRef.put(img);
};
The file gets uploaded to the storage, but with the wrong file type. The documentation of firebase storage tells us that when you upload a file without a file extension it automatically gets the application/octet-stream type. If no contentType metadata is specified and the file doesn't have a file extension, Cloud Storage defaults to the type application/octet-stream.
This is really strange because they are uploaded to the firebase storage with the right file extension.
I'm trying to upload images to the firebase storage. When I upload them to the storage, I see them with a type: application/octet-stream
instead of image/jpeg
or image/png
.
This is the code I use:
<input
type="file"
id="img"
name="filename"
accept="image/*"
onChange={(e) => {
handleChange(e);
}}
/>
const handleChange = async (e) => {
const imgRef = await firebase.storage().ref('images/' + image.name);
await imgRef.put(img);
};
The file gets uploaded to the storage, but with the wrong file type. The documentation of firebase storage tells us that when you upload a file without a file extension it automatically gets the application/octet-stream type. If no contentType metadata is specified and the file doesn't have a file extension, Cloud Storage defaults to the type application/octet-stream.
This is really strange because they are uploaded to the firebase storage with the right file extension.
-
You need to pass a name with an extension or pass
contentType
via metadata. See this answer here: stackoverflow./a/54303172/2144912 – cheshireoctopus Commented Jan 9, 2022 at 18:26
2 Answers
Reset to default 3I think this solution will apply to your case:
https://stackoverflow./a/54303172
You need to either specify the file extension using .child()
or add content type metadata to your upload file.
Can add meta data like that:
storageRef.put(file, {
contentType: 'image/png',
})
本文标签: javascriptFirebase storage file type is 39octetstream39 instead of 39pngjpg39Stack Overflow
版权声明:本文标题:javascript - Firebase storage file type is 'octet-stream' instead of 'pngjpg' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744098848a2590781.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论