无论如何缩小图像,都会发生Firebase存储“ PayloadTooLargeError”

时间:2018-08-23 19:33:19

标签: javascript firebase react-native firebase-storage

我正在用Firebase制作图像上载器,并像这样拍照并调整50%的大小:

onPress = async () => { 

    // return this.props.navigation.navigate('ImageManipulator')
    const { status: cameraPerm } = await Permissions.askAsync(Permissions.CAMERA);

    if (cameraPerm === 'granted') {

        const res = await ImagePicker.launchCameraAsync({
              allowsEditing: true
            , aspect: [4, 2]
        });

        if (res.hasOwnProperty('cancelled') && res.cancelled)
            this.setState({ imageData : false })

        else if (res.hasOwnProperty('uri') && res.uri) {
            const small = await this.resize(res.uri)
            this.setState({ imageData : small })
        }
    }
}

// this kills the program ... 
resize = async uri => {

    const res = await ImageManipulator.manipulate(
          uri
        , [{ resize: { width: 500 } }]
        , { compress: 0.5 }
        );

    return res;
}

给定图像uri,我用这段代码将其上传到Firebase存储中:

    const imgData = await fetch(uri);
    const blob    = await imgData.blob();

    const pathToImage = `post/${projectID}/profile.jpg`;

    const imgRes = await storage.ref(pathToImage)
        .put(blob)
        .then(x => console.log(`@here: `, x))
        .catch(e => console.log(e))

此代码将图像保存到firestore,但是我想在downloadUrl响应块中获得then,否则我收到错误消息:

PayloadTooLargeError: request entity too large
    at readStream 
    at getRawBody 
    at read 
    at jsonParser
    at Layer.handle [as handle_request]
    at trim_prefix 

过去类似的问题建议在express中进行一些设置,这无关紧要,因为我正在使用react-native在移动设备上。

0 个答案:

没有答案