react-firebase-file-uploader icon indicating copy to clipboard operation
react-firebase-file-uploader copied to clipboard

Fixed error getting name from metadata after upload

Open qnxdev opened this issue 4 years ago • 13 comments

var name = storageRef.child(filenameToUse).getMetadata().then(function (metadata) { return metadata.name; });

qnxdev avatar Dec 09 '20 08:12 qnxdev

I fixed with: task.snapshot.ref.name has been working well so far...

jayb967 avatar Dec 14 '20 19:12 jayb967

This is amazing !

Daniel-Monroy avatar Dec 26 '20 20:12 Daniel-Monroy

Is this going to be merged into master?

laurensnl avatar Jan 03 '21 12:01 laurensnl

merge please

alexneo2003 avatar Jan 06 '21 09:01 alexneo2003

Is this going to be merged into master?

Well, pull request is still there.

qnxdev avatar Jan 06 '21 09:01 qnxdev

merge please

You can use this

npm i https://github.com/qnxdev/react-firebase-file-uploader/tarball/master

qnxdev avatar Jan 06 '21 09:01 qnxdev

merge please

You can use this

npm i https://github.com/qnxdev/react-firebase-file-uploader/tarball/master

i'm using [email protected] and your fix for uploader and i'm having error

image

my 'filenameToUse' = '3267094a-6d54-495c-b093-57d2aa482947.png' and .split('/') from firebase is can't be used there because 'childPath' is not array correct me if i'm wrong

function from firebase

function child(path, childPath) { var canonicalChildPath = childPath .split('/') .filter(function (component) { return component.length > 0; }) .join('/'); if (path.length === 0) { return canonicalChildPath; } else { return path + '/' + canonicalChildPath; } }

alexneo2003 avatar Jan 06 '21 10:01 alexneo2003

merge please

You can use this npm i https://github.com/qnxdev/react-firebase-file-uploader/tarball/master

i'm using [email protected] and your fix for uploader and i'm having error

image

my 'filenameToUse' = '3267094a-6d54-495c-b093-57d2aa482947.png' and .split('/') from firebase is can't be used there because 'childPath' is not array correct me if i'm wrong

function from firebase

function child(path, childPath) { var canonicalChildPath = childPath .split('/') .filter(function (component) { return component.length > 0; }) .join('/'); if (path.length === 0) { return canonicalChildPath; } else { return path + '/' + canonicalChildPath; } }

I had the same problem and realize that filename argument is not resolved promise while .child(filename) is fired. Try: const handleUploadSuccess = async (filename) => { const name = await filename; setImage(name); setUploadProgress(100); setIsUploading(false); storage .ref() .child(name) .getDownloadURL() .then((url) => setImageURL(url)); };

DamianWrooby avatar Jan 08 '21 22:01 DamianWrooby

I fixed with: task.snapshot.ref.name has been working well so far...

this working for me

alexneo2003 avatar Jan 11 '21 07:01 alexneo2003

    task.on('state_changed', function (snapshot) {
      return onProgress && onProgress(Math.round(100 * snapshot.bytesTransferred / snapshot.totalBytes), task);
    }, function (error) {
      return onUploadError && onUploadError(error, task);
    }, function () {
      return storageRef.child(filenameToUse).getMetadata().then(function (metadata) {
        //return metadata.name;
        _this2.removeTask(task);
        return onUploadSuccess && onUploadSuccess(metadata.name, task);
      });
    });

marvintechdoo avatar Jan 18 '21 15:01 marvintechdoo

Is there any version of this lib working with the latest version of Firebase? I keep trying to fork this library and implement some of the fixes mentioned here and elsewhere and hitting weird bugs. Please help.

For example, when I implement @marvintechdoo's solution, I get an error on the second line of the fix telling me that onProgress is undefined. And of course it is defined in my tag, and even if it was not, the onProgress && part of the code should protect against that.

sarbogast avatar Feb 05 '21 12:02 sarbogast

@sarbogast you can check my fork, i'm fixed it for myself https://github.com/alexneo2003/react-firebase-file-uploader

alexneo2003 avatar Feb 05 '21 12:02 alexneo2003

@alexneo2003 Thanks a lot. It's the this.props. I was missing. Amazing.

sarbogast avatar Feb 05 '21 12:02 sarbogast