Firebase图像上传成功,但是页面加载时已部署的图像链接错误

时间:2018-10-07 05:46:45

标签: firebase react-native blob firebase-storage

我正在将图像从React Native ImagePickerIOS上传到Firebase存储。上载成功,但是部署的链接根本不起作用。在浏览器中加载链接时出现400错误。 Failed to load resource: the server responded with a status of 400 ()

对我要去哪里出错了吗?

   var image = new Blob([path]);
   var metadata = {
          contentType: 'image/jpeg'
        };

        var uploadTask = mediaStorage.child('media/image.jpeg').put(image, metadata);

        // Listen for state changes, errors, and completion of the upload.
        uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, // or 'state_changed'
          function (snapshot) {
            // Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
            var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
            console.log('Upload is ' + progress + '% done');
            switch (snapshot.state) {
              case firebase.storage.TaskState.PAUSED: // or 'paused'
                console.log('Upload is paused');
                break;
              case firebase.storage.TaskState.RUNNING: // or 'running'
                console.log('Upload is running');
                break;
            }
          },
          function (error) {

            // A full list of error codes is available at
            // https://firebase.google.com/docs/storage/web/handle-errors
            switch (error.code) {
              case 'storage/unauthorized':
                // User doesn't have permission to access the object
                break;

              case 'storage/canceled':
                // User canceled the upload
                break;

              case 'storage/unknown':
                // Unknown error occurred, inspect error.serverResponse
                break;
            }
          },
          function () {
            // Upload completed successfully, now we can get the download URL
            uploadTask.snapshot.ref.getDownloadURL().then(function (downloadURL) {
              console.log('File available at', downloadURL);
            });
          });

0 个答案:

没有答案