I am using node version 13.5.0. Google cloud storage gives an error named "FetchError, reason: read ECONNRESET" when trigger to upload. I parsed the images by multer@1.4.2 with express@4.17.1. I also created the bucket and service account correctly. Here is code:
const storage = new Storage({
projectId: 'ultra-brand-263520',
keyFilename: './google.json',
});
const bucketName = 'chimaera-img';
const bucket = storage.bucket(bucketName);
const gcsFileName = `${Date.now()}-${req.file.originalname}`;
const file = bucket.file(gcsFileName);
const stream = file.createWriteStream({
metadata: {
contentType: req.file.mimetype,
},
});
stream.on('error', (err) => {
req.file.cloudStorageError = err;
// next(err);
console.log(err)
});
stream.on('finish', () => {
req.file.cloudStorageObject = gcsFileName;
file.makePublic()
.then(() => {
req.file.gcsUrl = gcsHelpers.getPublicUrl(bucketName, gcsFileName);
// next();
console.log(req.file.gcsUrl)
});
});
stream.end(req.file.buffer);
and the error is:
at ClientRequest.<anonymous> (C:\Users\Md Tofazzal Haque\Documents\chimarea\brainiacs-chimaera-webapp\node_modules\gaxios\node_modules\node-fetch\lib\index.js:1455:11)
at ClientRequest.emit (events.js:305:20)
at TLSSocket.socketErrorListener (_http_client.js:423:9)
at TLSSocket.emit (events.js:305:20)
at emitErrorNT (internal/streams/destroy.js:84:8)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
message: 'request to https://storage.googleapis.com/upload/storage/v1/b/chimaera-img/o?name=1577912738314-Capture.PNG&uploadType=resumable failed, reason: read ECONNRESET',
type: 'system',
errno: 'ECONNRESET',
code: 'ECONNRESET',
config: {
method: 'POST',
url: 'https://storage.googleapis.com/upload/storage/v1/b/chimaera-img/o?name=1577912738314-Capture.PNG&uploadType=resumable',
params: [Object: null prototype] {
name: '1577912738314-Capture.PNG',
uploadType: 'resumable'
},
data: { contentType: 'image/png' },
headers: {
'X-Upload-Content-Type': 'image/png',
Authorization: 'Bearer ya29.c.KmK3BzZirjwc-_rTcRddTj3knZ1ujoZoJ9ez9hVaiUBitJRH1k4Qcd8GbvOHM8O8yO16EfzWUzKRtgxTEfaao_UHlj2hLxh8Wht8iJFRMm-NnFMpRdSo5Zp4DOaQTtG2v3hOGg',
'User-Agent': 'google-api-nodejs-client/5.7.0',
'x-goog-api-client': 'gl-node/13.5.0 auth/5.7.0',
'Content-Type': 'application/json',
Accept: 'application/json'
},
validateStatus: [Function (anonymous)],
paramsSerializer: [Function: paramsSerializer],
body: '{"contentType":"image/png"}',
responseType: 'json'
}
}