Closed kvv002 closed 2 years ago
I was able to reproduce the issue for both a pdf and a png. I was able to workaround by disabling request body compression and I suggest using that as a workaround for now.
I'll keep investigating the cause of the problem and try to identify if it is a server or client issue with compression.
I am not able to reproduce the problem using compression with either curl
or the Java SDK, so it seems to be specific to the handling of compressed bodies in the Node SDK core or axios. That said we have request body compression on by default and other [non-attachment] endpoints have certainly been working OK so there must be something specific about the attachment operations that trigger it.
It looks like the node-sdk-core assumes utf-8 during compression which would explain why it works OK for JSON content, but not these binary attachment types (and I guess why it could work for some PDF files). I've asked the node-sdk-core team for their thoughts on the problem and I expect a fix will have to come via the core in due course.
Just FYI, we're still waiting for an upsteam fix for this.
I made a contribution upstream https://github.com/IBM/node-sdk-core/pull/182, which we consumed here via #612 and released in version 0.0.23
.
It fixes the case where attachment
is provided as a ReadableStream
.
The case where an attachment
is provided as a Buffer
is still broken - the previous workaround of disabling compression still works or if compression is required a new workaround is to convert Buffer
to ReadableStream
before using the putAttachment
operation.
I will leave this issue open pending a fix for the latter case as well.
I made a PR upstream to fix the Buffer
case as well https://github.com/IBM/node-sdk-core/pull/184
Second part of the fix came in via https://github.com/IBM/cloudant-node-sdk/pull/616 and will be included in the next release.
Describe the bug
Create attachment as per the documentation, the attachment gets uploaded but the content gets corrupted. When I open cloudantDB UI, and I try to view my attachment,
To Reproduce
The below snippet for a pdf works fine and attachment content is not corrupted.
If I try to upload an image the same way as above, the image in the cloudant gets corrupted, below is my sample base64 image snippet
upload by using fs.readFile directly, and it has similar behavior as above.
uploaded using old cloudant driver, and It seems to be working fine.
Expected behavior The content of the data should not be corrupted for any file type.
Must gather (please complete the following information):