is there any size limit for pdf in hyperledger fab

2020-03-31 08:17发布

问题:

I have created small poc using hyperledger fabric and composer. In my project, I am uploading 2 files, for the first time the file getting uploaded but when I am trying to upload the second file of same size it show error in the composer

Unhandled error for request POST /api/UpdateContractDetails: Error: request entity too large at readStream (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/raw-body/index.js:196:17) at getRawBody (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/raw-body/index.js:106:12) at read (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/body-parser/lib/read.js:76:3) at jsonParser (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/body-parser/lib/types/json.js:127:5) at Layer.handle [as handle_request] (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:317:13) at /home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:335:12) at next (/home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/express/lib/router/index.js:275:10) at /home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/loopback/server/middleware/token.js:130:7 at /home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/loopback/common/models/access-token.js:108:15 at /home/ttandale/.nvm/versions/node/v6.11.2/lib/node_modules/composer-rest-server/node_modules/loopback/common/models/access-token.js:171:11 at _combinedTickCallback (internal/process/next_tick.js:73:7) at process._tickCallback (internal/process/next_tick.js:104:9)

回答1:

So technically, this is a Node question. Using Javascript, eg. fs.readFileSync(‘yourimageFile.jpg’).toString(‘base64’);, you should be able to convert the image to a Base64 string in your code. You can define 'String' for your chosen (modeled Asset type etc) field to host in Hyperledger Composer. The theory is that, once it is a string, it is sent to the chaincode just like any other string.

these links may help:

-> https://www.thepolyglotdeveloper.com/2016/02/convert-an-uploaded-image-to-a-base64-string-in-node-js/

-> https://belltane.wordpress.com/2017/03/27/storing-images-in-hyperledger-fabric-blockchain/