π Bug Report: Uploaded file has wrong type
SiyrisSoul opened this issue Β· comments
π Reproduction steps
When I try to upload an image to storage using the Node client the uploaded file has the wrong type.
- I create an image using
node-canvas
and save it a buffer:canvas.toBuffer()
- I upload the image to Appwrite storage:
InputFile.fromBuffer(buffer, 'name.png')
- It uploads as type
application/octet-stream
instead of PNG
The buffer should be valid as I am able to save and view the image locally using fs.writeFileSync("name.png", buffer);
π Expected behavior
I expect that it would store it as a png. From my understanding, it should be grabbing the type from the file name.
Here are some relevant links @stnguyen90 shared on Discord.
Node client:
sdk-for-node/lib/services/storage.js
Line 416 in 0b061a1
π Actual Behavior
It uploads as application/octet-stream
. I've also tried not using the .png
extension but that made no difference.
This is what it shows on the dashboard:
Here you can see the file names. I also attempted saving the base64 image which is the text file you see.
When opening the last file, with the .png
it shows this. You can see where it says PNG at the top.
π² Appwrite version
Version 0.15.x
π» Operating system
MacOS
𧱠Your Environment
I'm using "node-appwrite": "^7.0.2"
π Have you spent some time to check if this issue has been raised before?
- I checked and didn't find similar issue
π’ Have you read the Code of Conduct?
- I have read the Code of Conduct
I tested this using the playground-for-python (swapping InputFile.from_path()
with InputFile.from_bytes()
) and it worked.
I switched over to the playground-for-node and did the same thing, but I got application/octet-stream
even though $path
here was "/storage/uploads/app-file/files/6/2/e/0/62e0479c125ab67067f9.jpg"
.
I tried to download and open the file uploaded by the node-appwrite SDK, but it failed to open.
I think buffer.toString()
in the node-appwrite SDK might be causing a problem.
I tried removing the toString()
and the upload successfully worked with the right content type.
@CEOSiyris, for now, instead of InputFile.fromBuffer(buffer, 'name.png')
try this:
new InputFile(Readable.from(buffer), "name.png", Buffer.byteLength(buffer))
@CEOSiyris, for now, instead of
InputFile.fromBuffer(buffer, 'name.png')
try this:new InputFile(Readable.from(buffer), "name.png", Buffer.byteLength(buffer))
This works great, thank you! Will do that for now.
I confirm I am also affected by this. However InputFile
's constructor is not exposed in Typescript, thus for the workaround to work someone would need:
new (InputFile as any)(Readable.from(buffer), "name.png", Buffer.byteLength(buffer))
@CEOSiyris, for now, instead of
InputFile.fromBuffer(buffer, 'name.png')
try this:new InputFile(Readable.from(buffer), "name.png", Buffer.byteLength(buffer))
I've tried this workaround and the issue is still occurring. This is with Appwrite v1 and node SDK version 8.1.0
@JacksonToomey, it might be best for you to share your code on our Discord.