<legend id='P5te6'><style id='P5te6'><dir id='P5te6'><q id='P5te6'></q></dir></style></legend>
    <i id='P5te6'><tr id='P5te6'><dt id='P5te6'><q id='P5te6'><span id='P5te6'><b id='P5te6'><form id='P5te6'><ins id='P5te6'></ins><ul id='P5te6'></ul><sub id='P5te6'></sub></form><legend id='P5te6'></legend><bdo id='P5te6'><pre id='P5te6'><center id='P5te6'></center></pre></bdo></b><th id='P5te6'></th></span></q></dt></tr></i><div id='P5te6'><tfoot id='P5te6'></tfoot><dl id='P5te6'><fieldset id='P5te6'></fieldset></dl></div>

      <small id='P5te6'></small><noframes id='P5te6'>

        <bdo id='P5te6'></bdo><ul id='P5te6'></ul>

      <tfoot id='P5te6'></tfoot>
    1. 如何将图像 URI 转换为字节博览会

      时间:2023-11-29
      <legend id='716Wv'><style id='716Wv'><dir id='716Wv'><q id='716Wv'></q></dir></style></legend>

      <small id='716Wv'></small><noframes id='716Wv'>

            • <bdo id='716Wv'></bdo><ul id='716Wv'></ul>

                <i id='716Wv'><tr id='716Wv'><dt id='716Wv'><q id='716Wv'><span id='716Wv'><b id='716Wv'><form id='716Wv'><ins id='716Wv'></ins><ul id='716Wv'></ul><sub id='716Wv'></sub></form><legend id='716Wv'></legend><bdo id='716Wv'><pre id='716Wv'><center id='716Wv'></center></pre></bdo></b><th id='716Wv'></th></span></q></dt></tr></i><div id='716Wv'><tfoot id='716Wv'></tfoot><dl id='716Wv'><fieldset id='716Wv'></fieldset></dl></div>
                  <tbody id='716Wv'></tbody>
                <tfoot id='716Wv'></tfoot>

                本文介绍了如何将图像 URI 转换为字节博览会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 expo-image-picker 上传图片.但问题是我想通过 WebAPI 以字节的形式将图像发送到服务器.那么如何将图像 URI 转换为字节呢?如果有人有这方面的经验,请分享.

                I'm uploading image using expo-image-picker. but the issue is I want to send the image to the server through WebAPI in the form of Byte. So how can I convert the image URI into Byte? if anyone have experience on it so kindly share.

                 componentDidMount() {
                        this.getPermissionAsync();
                    }
                    getPermissionAsync = async () => {
                        if (Constants.platform.ios) {
                            const { status } = await Permissions.askAsync(Permissions.CAMERA_ROLL);
                            if (status !== 'granted') {
                                alert('Sorry, we need camera roll permissions to make this work!');
                            }
                        }
                    };
                    _pickImage = async () => {
                        try {
                            let result = await ImagePicker.launchImageLibraryAsync({
                                allowsEditing: true,
                                aspect: [4, 3],
                            });
                            console.log(result);
                
                            if (!result.cancelled) {
                                this.setState({ image: result.uri });
                            }
                        } catch (e) {
                            console.log(e);
                        }
                    };
                render() {
                        return (
                            <View>
                                <Card>
                                    <CardItem>
                                        <Body>
                                            <Button block primary onPress={() => this._pickImage()}>
                                                <Text>Add Activity</Text>
                                            </Button>
                                            {this.state.image && <Image source={{ uri: this.state.image }} style={{ width: 200, height: 200 }} /> }
                                        </Body>
                                    </CardItem>
                                </Card>
                            </View>
                        );
                    }
                

                世博小吃

                推荐答案

                你可以这样做:

                import { Buffer } from "buffer";
                
                _pickImage = async () => {
                  try {
                    let result = await ImagePicker.launchImageLibraryAsync({
                      base64: true,
                      allowsEditing: true,
                      aspect: [4, 3],
                    });
                
                    if (!result.cancelled) {
                      let imageByte = new Buffer(result.base64, "base64");
                
                      this.setState({ image: result.uri });
                    }
                  } catch (e) {
                      console.log(e);
                  }
                };
                

                注意:您将需要 buffer 包.

                NOTE: You will need buffer package.

                这篇关于如何将图像 URI 转换为字节博览会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Undefined is not an object (evalating 'React.PropTypes.N 下一篇:升级到 expo SDK 37.0.0 后,我的 stackNavigator 标头高度增加了一倍

                相关文章

              1. <i id='9Vur7'><tr id='9Vur7'><dt id='9Vur7'><q id='9Vur7'><span id='9Vur7'><b id='9Vur7'><form id='9Vur7'><ins id='9Vur7'></ins><ul id='9Vur7'></ul><sub id='9Vur7'></sub></form><legend id='9Vur7'></legend><bdo id='9Vur7'><pre id='9Vur7'><center id='9Vur7'></center></pre></bdo></b><th id='9Vur7'></th></span></q></dt></tr></i><div id='9Vur7'><tfoot id='9Vur7'></tfoot><dl id='9Vur7'><fieldset id='9Vur7'></fieldset></dl></div>
                  <bdo id='9Vur7'></bdo><ul id='9Vur7'></ul>
                <legend id='9Vur7'><style id='9Vur7'><dir id='9Vur7'><q id='9Vur7'></q></dir></style></legend>

                <small id='9Vur7'></small><noframes id='9Vur7'>

                  1. <tfoot id='9Vur7'></tfoot>