I’m trying to upload file on google firebase storage direct from url. I have review many ways and at the end, used the following solution:
const bucket = storage.bucket(bucketName);
const file = bucket.file(destPath + fileName);
return new Promise((resolve, reject) => {
try {
https.get(url, data => {
if (data && data.statusCode === 200) {
data.pipe(file.createWriteStream());
data.on("error", error => {
reject(error);
});
data.on("end", () => {
resolve(fileName);
});
} else {
const err = new Error(data.statusMessage);
err.code = data.statusCode;
data.removeAllListeners();
reject(err);
}
data.on("close", () => {
console.log("connection closed");
});
});
} catch (err) {
reject(err);
}
});
It’s working fine for many files (image, video, music, document) but getting issue in one video file which showing uploaded successfully on bucket but it’s not uploaded completely (uploaded a corrupted file). Also not getting any issue regarding the same. How can I sure that all my files will upload completely. May be there are many corrupted files which are not uploaded completely.
Is there any other way to upload directly to bucket? Please help for the same.
Have you tried to follow this documentation? CreateWriteStream. There is an example there on how to upload a file. Additionally, take a look in this other question, it is a bit similar to yours Upload a file from URL to Storage and I think it can be useful.