Hyperledger Fabric: Stub.getState returns empty buffer - hyperledger-fabric

here is our code to put the object:
let asset = {
owner: org,
sgtin: sgtin
};
let asset_as_string = JSON.stringify(asset);
console.log(asset_as_string);
let bytes = Buffer.from(asset_as_string);
console.log(bytes);
await stub.putState(sgtin, bytes);
and our code to retrieve it:
let bytes = await stub.getState(sgtin);
console.log(bytes);
here are the console log when putting the object:
{"owner":"jnj","sgtin":"00000"}
<Buffer 7b 22 6f 77 6e 65 72 22 3a 22 6a 6e 6a 22 2c 22 73 67 74 69 6e 22 3a 22 30 30 30 30 30 22 7d>
and when trying to get it:
<Buffer >
the buffer is empty and causes an error when we try to parse it:
SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at update (/usr/local/src/chaincode.js:108:24)
how to fix this?

The problem here was that Fabric was not writing anything to the blockchain database. The call to invoke would return without any signs of failure, something like
[chaincodeCmd] chaincodeInvokeOrQuery -> INFO 067 Chaincode invoke successful. result: status:200 payload:"\"OK\""
(another reason we are regretting using fabric) but when we looked in peer logs, we saw some error. Something like could not get endorsement. This gave us a clue since we had set our endorsement policy to AND but were invoking chaincode against only 1 peer. When we changed the invoke command to execute chaincode against all peers, the error vanished.
root#d0931df7a681:/# peer chaincode invoke -C mychannel -n mycc -c '{"Args":["create","00000"]}' -o orderer1-ord:7050 --tls --cafile /data/ord-ca-chain.pem --clientauth $ORDERER_CONN_ARGS --peerAddresses peer1-jnj:7051 --tlsRootCertFiles data/jnj-ca-chain.pem --peerAddresses peer1-kp:7051 --tlsRootCertFiles data/kp-ca-chain.pem --peerAddresses peer1-cvs:7051 --tlsRootCertFiles data/cvs-ca-chain.pem

Related

Send multipart/form-data with axios in AWS Lambda function: source.on is not a function

I have a lambda function written in node js. My front end application is sending formdata in the body as a POST request to my lambda function. The goal of the lambda is to send the formData to a backend service. My issue is I don't know how to process the formdata within the lambda function.
I have the following modules packages: lambda-multipart-parser and form-data.
This is the output of the lambda-parser:
const parser = require('lambda-multipart-parser');
// inside of handler
const result = await parser.parse(event);
console.log('result',result)
Result:
result {
files: [
{
content: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 01 2c 01 2c 00 00 ff e1 03 66 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 09 01 0f 00 02 00 00 00 06 00 00 ... 141038 more bytes>,
filename: 'IMG_0037 - Copy.JPG',
contentType: 'image/jpeg',
encoding: '7bit',
fieldname: 'files'
},
{
content: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 01 2c 01 2c 00 00 ff e1 03 66 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 09 01 0f 00 02 00 00 00 06 00 00 ... 141038 more bytes>,
filename: 'IMG_0037.JPG',
contentType: 'image/jpeg',
encoding: '7bit',
fieldname: 'files'
}
]
Then I append the results to form data and try and make the request:
// Add files to formData
const formData = new FormData();
result.files.forEach(file => {
formData.append('files', file);
});
const formHeaders = formData.getHeaders();
formData.submit({
host: www.example.com,
headers: formHeaders
})
I then get the following error: source.on is not a function
I've looked online and tried quite a few different things but I can't seem to get this to work.
Any help would be much appreciated!
Thank You
EDIT
Complete stack trace
TypeError: source.on is not a function
at Function.DelayedStream.create (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\delayed-stream\lib\delayed_stream.js:33:10)
at FormData.CombinedStream.append (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\combined-stream\lib\combined_stream.js:45:37)
at FormData.append (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\form-data\lib\form_data.js:75:3)
at C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\.webpack\service\src\upload\handler.js:1:3543
at Array.forEach (<anonymous>)
at r.handler (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\.webpack\service\src\upload\handler.js:1:3529)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async InProcessRunner.run (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\serverless-offline\dist\lambda\handler-runner\in-process-runner\InProcessRunner.js:211:24)
at async LambdaFunction.runHandler (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\serverless-offline\dist\lambda\LambdaFunction.js:355:20)
at async hapiHandler (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\serverless-offline\dist\events\http\HttpServer.js:533:18)
at async module.exports.internals.Manager.execute (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\#hapi\hapi\lib\toolkit.js:45:28)
at async Object.internals.handler (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\#hapi\hapi\lib\handler.js:46:20)
at async exports.execute (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\#hapi\hapi\lib\handler.js:31:20)
at async Request._lifecycle (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\#hapi\hapi\lib\request.js:312:32)
at async Request._execute (C:\Users\206591256\Documents\Personal\Sage-Projects\Eagle\football\eagle-api\node_modules\#hapi\hapi\lib\request.js:221:9)
offline: (λ: upload) RequestId: ckxajn1hn0002i4nwegzrbsx5 Duration: 283.18 ms Billed Duration: 284 ms

How to convert image buffer to form-data in node.js?

I have a buffer of an image like:
<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 04 03 03 03 03 02 04 03 03 03 04 04 04 05 06 0a 06 06 05 05 06 0c 08 09 07 ... 231835 more bytes>
and I have installed form-data module from npm.
I need to send this image file as form-data, I tried:
const form = new FormData();
form.append("image", buffer, { filename: "london.jpg" });
But it didn't work, how can I solve this problem?
I finally found a way to resolve the issue by using request module.
https://www.npmjs.com/package/request
request.post({
url,
formData: {
image: {
value: file.buffer, // Give your node.js buffer to here
options: {
filename: file.originalname, // filename
contentType: file.mimetype // file content-type
}
}
}
},(error, http_response, body) => {
});

The "chunk" argument must be of type string or an instance of Buffer. Received an instance of ArrayBuffer

I have passed an image obtained from Microsoft Graph API to pictureURL() function.
But getting this error:
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer. Received an instance of ArrayBuffer
at ClientRequest.end (_http_outgoing.js:768:13)
at features.constructor.writeBody (K:\Project\project-backend\node_modules\aws-sdk\lib\http\node.js:137:14)
at features.constructor.handleRequest (K:\Project\project-backend\node_modules\aws-sdk\lib\http\node.js:105:12)
at executeSend (K:\Project\project-backend\node_modules\aws-sdk\lib\event_listeners.js:342:29)
at Request.SEND (K:\Project\project-backend\node_modules\aws-sdk\lib\event_listeners.js:356:9)
I want to upload the image obtained from Graph API to s3 bucket.
Microsoft Graph API for getting the image of a user-
https://graph.microsoft.com/v1.0/users/${id | userPrincipalName}/photo/$value
Function in which I am passing the obtained image is -
async pictureURL(image, userID) {
try {
const uploadParams = { Bucket: config.s3bucket.name };
const bufferData = await image.arrayBuffer();
uploadParams.Body = bufferData;
uploadParams.Key = 'example.jpg'// path.basename(image);
s3.putObject(uploadParams, (err, data) => {
if (err) {
console.log('Error', err);
return;
}
console.log('Upload Success', data.Location);
return data.Location;
});
} catch (error) {
console.log(error)
}
}
image format returned by the graph-api -
image: Blob {
[Symbol(type)]: 'image/jpeg',
[Symbol(buffer)]: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 01 00 60 00 60 00 00 ff db 00 43 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ... 4355 more bytes>
}

Firestore / gRPC behind a corporate firewall / proxy

Our company has built an electron application using Firestore and now we are trying to deploy the application behind a corporate proxy and firewall (customer environment). After setting the proxy authentication settings using electrons app.on('login') all network requests in the application are successful, except for the firestore connection.
We receive the following error:
[2018-09-21T09:09:13.556Z] #firebase/firestore: Firestore (5.5.0) [Connection]: GRPC stream error. Code: 14 Message: 14 UNAVAILABLE: Connect Failed
[2018-09-21T09:09:13.557Z] #firebase/firestore: Firestore (5.5.0) [PersistentStream]: close with error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connect Failed
[2018-09-21T09:09:13.557Z] #firebase/firestore: Firestore (5.5.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unavailable]: 14 UNAVAILABLE: Connect Failed
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
We have also tried to debug gRPC which is used by Firestore with the following log output:
I0921 11:39:18.014000000 8920 src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:292] [pick_first 138D9818] subchannel list 08E19208 index 7 of 11 (subchannel 138B9138): starting watch: requesting connectivity change notification (from IDLE)
I0921 11:39:18.016000000 8920 connectivity_state.cc:116] CONWATCH: 138B91A8 subchannel: from IDLE [cur=IDLE] notify=08F0B0C4
I0921 11:39:18.016000000 8920 connectivity_state.cc:164] SET: 138B91A8 subchannel: IDLE --> CONNECTING [state_change] error=00000000 "No Error"
I0921 11:39:18.018000000 8920 connectivity_state.cc:190] NOTIFY: 138B91A8 subchannel: 08F0B0C4
I0921 11:39:18.019000000 8920 tcp_client_custom.cc:139] CLIENT_CONNECT: 134C5B98 ipv4:172.217.16.202:443: asynchronously connecting
I0921 11:39:18.020000000 8920 src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:404] [pick_first 138D9818] subchannel list 08E19208 index 7 of 11 (subchannel 138B9138): connectivity changed: state=CONNECTING, error="No Error", shutting_down=0
I0921 11:39:18.021000000 8920 connectivity_state.cc:164] SET: 138D9848 pick_first: CONNECTING --> CONNECTING [connecting_changed] error=00000000 "No Error"
I0921 11:39:18.021000000 8920 src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:313] [pick_first 138D9818] subchannel list 08E19208 index 7 of 11 (subchannel 138B9138): renewing watch: requesting connectivity change notification (from CONNECTING)
I0921 11:39:18.026000000 8920 connectivity_state.cc:116] CONWATCH: 138B91A8 subchannel: from CONNECTING [cur=CONNECTING] notify=08F0B0C4
I0921 11:39:18.027000000 8920 completion_queue.cc:851] grpc_completion_queue_next(cq=08DED7E0, deadline=gpr_timespec { tv_sec: -9223372036854775808, tv_nsec: 0, clock_type: 0 }, reserved=00000000)
I0921 11:39:18.028000000 8920 completion_queue.cc:951] RETURN_EVENT[08DED7E0]: QUEUE_TIMEOUT
I0921 11:39:18.030000000 8920 tcp_custom.cc:348] Creating TCP endpoint 134C5B98
I0921 11:39:18.030000000 8920 tcp_client_custom.cc:69] CLIENT_CONNECT: ipv4:172.217.16.202:443: on_alarm: error="Cancelled"
I0921 11:39:18.030000000 8920 handshaker.cc:141] handshake_manager 034B6840: adding handshaker http_connect [137A6430] at index 0
I0921 11:39:18.030000000 8920 ssl_transport_security.cc:211] HANDSHAKE START - TLS client start_connect - !!!!!!
I0921 11:39:18.030000000 8920 ssl_transport_security.cc:211] LOOP - TLS client enter_early_data - !!!!!!
I0921 11:39:18.030000000 8920 ssl_transport_security.cc:211] LOOP - TLS client read_server_hello - !!!!!!
I0921 11:39:18.031000000 8920 handshaker.cc:141] handshake_manager 034B6840: adding handshaker security [08F078C8] at index 1
I0921 11:39:18.031000000 8920 handshaker.cc:212] handshake_manager 034B6840: error="No Error" shutdown=0 index=0, args={endpoint=13454A30, args=08E1AC60 {size=8: grpc.primary_user_agent=grpc-node/1.13.1, grpc.client_channel_factory=58CBB994, grpc.channel_credentials=134C5318, grpc.server_uri=dns:///firestore.googleapis.com, grpc.default_authority=firestore.googleapis.com, grpc.http2_scheme=https,
grpc.security_connector=08EDF460, grpc.subchannel_address=ipv4:172.217.16.202:443}, read_buffer=08D55870 (length=0), exit_early=0}
I0921 11:39:18.031000000 8920 handshaker.cc:253] handshake_manager 034B6840: calling handshaker http_connect [137A6430] at index 0
I0921 11:39:18.031000000 8920 handshaker.cc:212] handshake_manager 034B6840: error="No Error" shutdown=0 index=1, args={endpoint=13454A30, args=08E1AC60 {size=8: grpc.primary_user_agent=grpc-node/1.13.1, grpc.client_channel_factory=58CBB994, grpc.channel_credentials=134C5318, grpc.server_uri=dns:///firestore.googleapis.com, grpc.default_authority=firestore.googleapis.com, grpc.http2_scheme=https,
grpc.security_connector=08EDF460, grpc.subchannel_address=ipv4:172.217.16.202:443}, read_buffer=08D55870 (length=0), exit_early=0}
I0921 11:39:18.031000000 8920 handshaker.cc:253] handshake_manager 034B6840: calling handshaker security [08F078C8] at index 1
I0921 11:39:18.032000000 8920 tcp_custom.cc:234] WRITE 134C5B98 (peer=ipv4:172.217.16.202:443): 16 03 01 00 9f 01 00 00 9b 03 03 20 0d 33 b4 b9 36 9c bc b1 56 cf f9 8b 2c 96 35 7a 10 05 c7 42 8f 0b e8 f5 55 b9 5b d2 03 9e 40 00 00 08 c0 2b c0 2c c0 2f c0 30 01 00 00 6a ff 01 00 01 00 00 00 00 1d 00 1b 00 00 18 66 69 72 65 73 74 6f 72 65 2e 67 6f 6f 67 6c 65 61 70 69 73 2e 63 6f 6d 00 17 00 00 00
23 00 00 00 0d 00 14 00 12 04 03 08 04 04 01 05 03 08 05 05 01 08 06 06 01 02 01 33 74 00 00 00 10 00 0e 00 0c 08 67 72 70 63 2d 65 78 70 02 68 32 00 0b 00 02 01 00 00 0a 00 04 00 02 00 17 '........... .3..6...V...,.5z...B....U.[...#....+.,./.0...j..............firestore.googleapis.com.....#..........................3t.........grpc-exp.h2..............'
I0921 11:39:18.033000000 8920 completion_queue.cc:851] grpc_completion_queue_next(cq=08DED7E0, deadline=gpr_timespec { tv_sec: -9223372036854775808, tv_nsec: 0, clock_type: 0 }, reserved=00000000)
I0921 11:39:18.044000000 8920 completion_queue.cc:951] RETURN_EVENT[08DED7E0]: QUEUE_TIMEOUT
I0921 11:39:18.046000000 8920 tcp_custom.cc:217] write complete on 134C5B98: error="No Error"
I0921 11:39:18.046000000 8920 resource_quota.cc:795] RQ anonymous_pool_8f00c70 ipv4:172.217.16.202:443: alloc 8192; free_pool -> -8192
I0921 11:39:18.046000000 8920 resource_quota.cc:292] RQ: check allocation for user 08DDBA00 shutdown=0 free_pool=-8192
I0921 11:39:18.047000000 8920 resource_quota.cc:318] RQ anonymous_pool_8f00c70 ipv4:172.217.16.202:443: grant alloc 8192 bytes; rq_free_pool -> 9223372036854767615
I0921 11:39:18.048000000 8920 tcp_custom.cc:174] TCP:134C5B98 read_allocation_done: "No Error"
I0921 11:39:18.048000000 8920 tcp_custom.cc:191] Initiating read on 134C5B98: error="No Error"
I0921 11:39:18.050000000 8920 completion_queue.cc:851] grpc_completion_queue_next(cq=08DED7E0, deadline=gpr_timespec { tv_sec: -9223372036854775808, tv_nsec: 0, clock_type: 0 }, reserved=00000000)
I0921 11:39:18.052000000 8920 completion_queue.cc:951] RETURN_EVENT[08DED7E0]: QUEUE_TIMEOUT
I0921 11:39:18.056000000 8920 resource_quota.cc:818] RQ anonymous_pool_8f00c70 ipv4:172.217.16.202:443: free 8192; free_pool -> 8192
I0921 11:39:18.057000000 8920 tcp_custom.cc:128] TCP:134C5B98 call_cb 08F079B8 58B7D4B0:08F078C8
I0921 11:39:18.064000000 8920 tcp_custom.cc:132] read: error={"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}
D0921 11:39:18.065000000 8920 security_handshaker.cc:129] Security handshake failed: {"created":"#1537522758.065000000","description":"Handshake read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]}
I0921 11:39:18.066000000 8920 tcp_custom.cc:286] TCP 134C5B98 shutdown why={"created":"#1537522758.065000000","description":"Handshake read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]}
I0921 11:39:18.067000000 8920 handshaker.cc:212] handshake_manager 034B6840: error={"created":"#1537522758.065000000","description":"Handshake read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]} shut
down=0 index=2, args={endpoint=00000000, args=00000000 {size=0: (null)}, read_buffer=00000000 (length=0), exit_early=0}
I0921 11:39:18.069000000 8920 handshaker.cc:240] handshake_manager 034B6840: handshaking complete -- scheduling on_handshake_done with error={"created":"#1537522758.065000000","description":"Handshake read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\
grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]}
I0921 11:39:18.072000000 8920 connectivity_state.cc:164] SET: 138B91A8 subchannel: CONNECTING --> TRANSIENT_FAILURE [connect_failed] error=08E97DF8 {"created":"#1537522758.071000000","description":"Connect Failed","file":"..\deps\grpc\src\core\ext\filters\client_channel\subchannel.cc","file_line":641,"grpc_status":14,"referenced_errors":[{"created":"#1537522758.065000000","description":"Handshake
read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]}]}
I0921 11:39:18.075000000 8920 connectivity_state.cc:190] NOTIFY: 138B91A8 subchannel: 08F0B0C4
I0921 11:39:18.076000000 8920 subchannel.cc:646] Connect failed: {"created":"#1537522758.065000000","description":"Handshake read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]}
I0921 11:39:18.076000000 8920 resource_quota.cc:508] RU shutdown 08DDBA00
I0921 11:39:18.078000000 8920 src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:404] [pick_first 138D9818] subchannel list 08E19208 index 7 of 11 (subchannel 138B9138): connectivity changed: state=TRANSIENT_FAILURE, error={"created":"#1537522758.071000000","description":"Connect Failed","file":"..\deps\grpc\src\core\ext\filters\client_channel\subchannel.cc","file_line":641,"grpc_sta
tus":14,"referenced_errors":[{"created":"#1537522758.065000000","description":"Handshake read failed","file":"..\deps\grpc\src\core\lib\security\transport\security_handshaker.cc","file_line":321,"referenced_errors":[{"created":"#1537522758.056000000","description":"EOF","file":"..\deps\grpc\src\core\lib\iomgr\tcp_uv.cc","file_line":107}]}]}, shutting_down=0
I0921 11:39:18.079000000 8920 src/core/ext/filters/client_channel/lb_policy/subchannel_list.h:332] [pick_first 138D9818] subchannel list 08E19208 index 7 of 11 (subchannel 138B9138): stopping connectivity watch
How can this connectivity problem be solved? Which settings need to be changed in the corporate proxy or firewall in order for Firestore / gRPC to be able to connect?
As can be seen in the source code, the node.js client library accesses Firestore through gRPC at firestore.googleapis.com on port 443.
So for your application to work with Firestore successfully, the firewall/proxy must allow access to firestore.googleapis.com on port 443 via TCP. Why this doesn't work at the moment is a question to the current configuration of the firewall/proxy, most probably it is blocked by default in some catch-all rule.
Warning: GRPC currently only supports HTTP Basic Auth for proxies. The proxy authentication method here will currently not work, if the proxy requires authentication via Digest. I have filed an issue for it here: https://github.com/grpc/grpc/issues/18250
There seem to be two workarounds currently:
Possibility 1: The solution is to set the environment variables for http_proxy and https_proxy before loading the Electron BrowserWindow that initiates the Firestore connection.
An possible way is to ask for proxy credentials in the BrowserWindow and return them to the main process using an event (in this example set-proxy-url). After setting the environment variables correctly for gRPC to pick them up, reload the BrowserWindow (or open a new one).
Example code (main):
ipcMain.on('set-proxy-url', (event: Electron.Event, arg: any) => {
if (arg.authInfo.isProxy) {
// In our case this is a http proxy (HTTPS is tunneled)
const httpUrl = `http://${arg.user}:${arg.pass}#${arg.authInfo.host}:${arg.authInfo.port}`
process.env.http_proxy = httpUrl
process.env.https_proxy = httpUrl
// TODO: Reload the BrowserWindow that uses Firestore
}
})
Example code (renderer):
ipcRenderer.send('set-proxy-url', {
authInfo, // This comes from app.on('login', (event, webContents, request, authInfo, callback) => { ... }
user: usernameRetrievedFromUser,
pass: passwordRetrievedFromUser
})
Possibility 2: Configure a VPN tunnel and configure CNAME in your internal DNS to point *.googleapis.com to private.googleapis.com as explained here.

Save video file received from multipart form in Serverless Offline

I have an website running Angular4 with a simple form uploading data using ng2-file-upload. I'm sending those files to a Node.js-based serverless offline server where my intention is to simply write those files received from the form to disk.
I tried to do in many different ways, and in the end I found this right here that parses that form from the event into a json. The resulting json contains a buffer in one of the fields with the video data like so:
{ Host: 'localhost:3000',
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko/20100101 Firefox/59.0',
Accept: '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
Referer: 'http://localhost:4200/myupload',
'Content-Length': 2391623,
'Content-Type': 'multipart/form-data; boundary=---------------------------2125290100942661667805976894',
Origin: 'http://localhost:4200',
Connection: 'keep-alive' }
{ file:
{ type: 'file',
filename: 'y9K18CGEeiI.webm',
contentType: 'video/webm',
content: <Buffer 1a 45 e3 01 00 00 00 00 00 00 1f 42 fd fd 01 42 fd fd 01 42 fd 04 42 fd 08 42 fd fd 77 65 62 6d 42 fd fd 02 42 fd fd 02 18 53 fd 67 01 00 00 00 00 14 ... > } }
Now what I'm trying to do is to save the file in the buffer using fs:
module.exports.handler = (event, context, callback) => {
let data = multipart.parse(event, false);
fs.writeFile('meme.webm', data.file.content, 'binary', function(err) {
if(err) {
console.log(err);
} else {
console.log('saved!');
}
});
// etc ...
};
The file saves to the disk with the correct size (1.3MB), same as the original file. Unfortunately, I can't seem to open it on the other side and I assume it's either because othe encoding or because of the way I'm writing it to disk. Any ideas?
For anyone with this problem, check this issue right here. It's a problem with serverless offline converting file data and there's not much that can be done it seems other than applying the fork.

Resources