使用react native提取blob和react native图像裁剪器上传多个图像

时间:2019-09-02 12:47:38

标签: react-native react-native-android react-native-ios

我想使用react native图像选择器上载多个图像并获取blob,对于单个图像来说很好,但对于图像数组,在chrome控制台中获取blob响应为空。我尝试了其他一些包装,但是没有运气。

我已经尝试过文档选择器,图像选择器等。

ImagePicker.openPicker({
                        multiple: true,
                        includeBase64: true,
                        mediaType: 'photo',
                        forceJpg: true,

                    }).then(images => {
                        console.log('crop picker:');
                        console.log(images[0].path);
                        if (images.length !== 0) {
                            let Photo = [];
                            for (let i = 0; i < images.length; i++) {
                                        let uri = images[i].path
                                        // let uri = images[i].path.replace('file:///', '')

                                // MultipleImageNames.push((Math.ceil(new Date().getTime())).toString().replace(".", "") + ".jpg")
                                // MutlipleImagesFiles.push(images[i].data)
                                Photo.push({
                                    name: 'file',
                                    type: 'image/jpeg',
                                    filename: (Math.ceil(new Date().getTime())).toString().replace(".", "") + ".jpg",
                                    data: RNFetchBlob.wrap(uri)
                                });
                            }
                            this.setState({Photos: Photo}, () => this._ImageSelect())
                        }
                    });
/////////////////////////////////////////////////////////////
and the fetch blob code is: 
    _ImageSelect() {
    console.log('Mulitimage upload Rsp: ');
    console.log( this.state.Photos);

    RNFetchBlob.fetch('POST', URLS.Link() + 'upload', {
            Authorization: "Bearer access-token",
            otherHeader: "foo",
            'Content-Type': 'multipart/form-data',
        },
        this.state.Photos
    ).then((resp) => {
        console.log('Mulitimage upload Rsp: ');
        console.log(resp);
        if (resp.respInfo.status == 200) {
            Alert.alert(
                '',
                'تصویر  ارسال شد',
                [
                    {
                        text: 'بستن',
                        onPress: () => null
                    },
                ],
                {cancelable: false}
            );
        } else {
            Alert.alert(
                '',
                'تصویر ارسال نشد',
                [
                    {text: 'بستن', onPress: () => null},
                ],
                {cancelable: false}
            );
        }
    }).catch((err) => {
        this.setState({LoadingP: false})
        console.error(err)
    })
}

0 个答案:

没有答案