You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2020/01/23 13:21:21 UTC

[GitHub] [couchdb-nano] techaddicted opened a new issue #195: db.attachment.get function corrupts attachment

techaddicted opened a new issue #195: db.attachment.get function corrupts attachment
URL: https://github.com/apache/couchdb-nano/issues/195
 
 
   <!--- Provide a general summary of the issue in the Title above -->
   
   ## Expected Behavior
   <!--- If you're describing a bug, tell us what should happen -->
   <!--- If you're suggesting a change/improvement, tell us how it should work -->
   Insert attachment into couchdb with db.attachment.insert as seen in official documentation [Insert](https://www.npmjs.com/package/nano#dbattachmentinsertdocname-attname-att-contenttype-params-callback) and retrieving the attachment from couchdb with db.attachment.get as seen in official documentation [get](https://www.npmjs.com/package/nano#dbattachmentgetdocname-attname-params-callback) should provide you with the attachment in its original form.
   
   ## Current Behavior
   <!--- If describing a bug, tell us what happens instead of the expected behavior -->
   <!--- If suggesting a change/improvement, explain the difference from current behavior -->
   Retrieving the attachment via attachment.get causes the attachment to be corrupted. Examples for corrupted attachments are pictures in jpg and png format and other file types such as docx. The only attachment not corrupted is txt files.
   Corrupted files are roughly 2x size and feature the wrong file signature.
   It must be noted that this seems not to be a couchdb server issue, since the attachment, in the case of an image, is displayed correctly in the management web gui. In addition, the python couchdb client does not corrupt the attachment, so it must be an error in couchdb-nano.
   
   ## Steps to Reproduce (for bugs)
   <!--- Provide a link to a live example, or an unambiguous set of steps to -->
   <!--- reproduce this bug. Include code to reproduce, if relevant -->
   1. Setup couchdb 2.3.1 with default setting
   2. Insert attachment into couchdb as seen in official couchdb-nano documentation or via web gui upload
   3. Get attachment via couchdb-nano attachment.get function as seen in official couchdb-nano documentation
   4. Try to open image results in error like "fatal error reading jpg image file: not a jpg file"
   
   ## Context
   <!--- How has this issue affected you? What are you trying to accomplish? -->
   <!--- Providing context helps us come up with a solution that is most useful in the real world -->
   - Unable to retrieve attachment in a non corrupt form
   ## Your Environment
   <!--- Include as many relevant details about the environment you experienced the bug in -->
   * Version used: couchdb: 2.3.1, couchdb-nano: 8.1.0, node 8.17.0
   * Operating System and version (desktop or mobile): Ubuntu 18.04

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [couchdb-nano] noxsradamus commented on issue #195: db.attachment.get function corrupts attachment

Posted by GitBox <gi...@apache.org>.
noxsradamus commented on issue #195: db.attachment.get function corrupts attachment
URL: https://github.com/apache/couchdb-nano/issues/195#issuecomment-577703452
 
 
   I've tried to replicate this issue by manually downloading an attachment via nodejs requests module. I ran in the exact same issue. With requests module can be solved by the steps shown [in this stackoverflow post](https://stackoverflow.com/questions/56758121/image-download-via-node-request-module-is-corrupt/56758284#56758284) .  In the end the request module requires the encoding to be passed as null. And second fs.writeFile requires the encoding to be set as binary. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [couchdb-nano] glynnbird commented on issue #195: db.attachment.get function corrupts attachment

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #195: db.attachment.get function corrupts attachment
URL: https://github.com/apache/couchdb-nano/issues/195#issuecomment-591916634
 
 
   Steps to reproduce:
   
   ```js
   const Nano = require('nano')
   const fs = require('fs')
   
   const main = async () => {
     const nano = Nano(process.env.COUCH_URL)
     const db = nano.db.use('a')
     const att = await db.attachment.get('b','dog.jpg')
     fs.writeFileSync('dog.jpg', att)  
   }
   
   main()
   ```
   
   with a document like this: 
   
   ```js
   {
     "_id": "b",
     "_rev": "3-c0a1ce76712f8f1c3eb3d296c0cf4e29",
     "x": 1,
     "y": 2,
     "_attachments": {
       "dog.jpg": {
         "content_type": "image/jpeg",
         "revpos": 2,
         "digest": "md5-2Vq3z0rHeNN+DkJk1BVgCg==",
         "length": 93651,
         "stub": true
       }
     }
   }
   ```
   
   Confirmed that it fails on nano8.1 but passes on Nano master.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [couchdb-nano] glynnbird closed issue #195: db.attachment.get function corrupts attachment

Posted by GitBox <gi...@apache.org>.
glynnbird closed issue #195: db.attachment.get function corrupts attachment
URL: https://github.com/apache/couchdb-nano/issues/195
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [couchdb-nano] glynnbird commented on issue #195: db.attachment.get function corrupts attachment

Posted by GitBox <gi...@apache.org>.
glynnbird commented on issue #195: db.attachment.get function corrupts attachment
URL: https://github.com/apache/couchdb-nano/issues/195#issuecomment-592427762
 
 
   Works on Nano 8.2.0

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services