我開發了一個Firebase雲端功能,可處理上傳圖片上的多個操作。 我的代碼基於this documentation article和this Cloud Function example。因此,它使用Google Cloud Storage package。Firebase存儲和雲端功能 - ECONNRESET
它做工精細,幾乎所有的時間,但上載或從存儲刪除時,有時我得到這個錯誤:
Error: read ECONNRESET
at exports._errnoException (util.js:1026:11)
at TLSWrap.onread (net.js:569:26)
我用我的應用程序的默認鬥,由event.data.bucket
引用。
讓我知道你是否需要額外的信息或代碼片斷,即使我的代碼非常接近之前鏈接的函數示例。
我發現this GitHub issue,但我檢查了我每次都會返回一個承諾。例如,這裏是觸發錯誤的刪除部分:
index.js
exports.exampleFunction = functions.storage.object().onChange(event => {
return f_thumbnails.exampleFunction(event);
});
example_function.js
module.exports = exports = function (_admin, _config) {
admin = _admin;
config = _config;
return {
"exampleFunction": function (event) {
return exampleFunction(event);
}
};
};
const exampleFunction = function (event) {
const gcsSourceFilePath = event.data.name;
const gcsSourceFilePathSplit = gcsSourceFilePath.split('/');
const gcsBaseFolder = gcsSourceFilePathSplit.length > 0 ? gcsSourceFilePathSplit[0] : '';
const gcsSourceFileName = gcsSourceFilePathSplit.pop();
const gceSourceFileDir = gcsSourceFilePathSplit.join('/') + (gcsSourceFilePathSplit.length > 0 ? '/' : '');
// Not an image
if (!event.data.contentType.startsWith('image/')) {
console.log('Not an image !');
return;
}
// Thumbnail
if (gcsSourceFileName.startsWith(config.IMAGES_THUMBNAIL_PREFIX)) {
console.log('Thumbnail !');
return;
}
const bucket = gcs.bucket(event.data.bucket);
const gcsThumbnailFilePath = gceSourceFileDir + config.IMAGES_THUMBNAIL_PREFIX + gcsSourceFileName;
// File deletion
if (event.data.resourceState === 'not_exists') {
console.log('Thumbnail deletion : ' + gcsThumbnailFilePath);
return bucket.file(gcsThumbnailFilePath).delete().then(() => {
console.log('Deleted thumbnail ' + gcsThumbnailFilePath);
});
}
...
任何機會,我們可以看到'...'後面發生了什麼? – Nivco
您已將所有代碼對應於縮略圖刪除。我的函數應該停止在'return bucket.file(gcsThumbnailFilePath).delete()。'部分。我在Firebase後端得到了以前的'console.log('縮略圖刪除:'+ gcsThumbnailFilePath);'但不是承諾成功完成之一。 – OlivierH
我沒有看到ECONNRESET實際發生的任何原因。這是否經常發生? – Nivco