如何在react native中将base64编码的png签名上传到服务器

how to upload base64 encoded png of signature to server in react native

我是 React Native 的新手。我正在尝试使用 formData 将 base64 编码的 png 上传到服务器。但我不断出错。网络请求失败。请帮忙。谢谢。 这是代码

this.setState({base64: `data:image/jpeg;base64,${result.encoded}`})
console.log(this.state.base64)

  formData.append('digital_signature', 
           {
             
               uri:this.state.base64,         
              // uri: this.state.singleFileADH1,
              name: 'digital_signature.jpg',
              type: 'image/*'
          }
       );

   fetch('https://abc.tech/Android_API_CI/upload_multipart_data',
      {
        method: 'post',
          body : formData,
          
        headers: {
          'Content-Type': 'multipart/form-data;',
        },
        
      }

<SignatureCapture
          style={styles.signature}
          ref="sign"
          onSaveEvent={this._onSaveEvent}
          onDragEvent={this._onDragEvent}
          showNativeButtons={false}
          // minStrokeWidth={-10}
          // saveImage={true}
          showTitleLabel={false}
          viewMode={'portrait'}
        />

 const file = {
      uri:
        Platform.OS == 'android'
          ? ImageUri.path
          : `file://${ImageUri.path}`,
      name: 'image.jpg',
      type: ImageUri.mime, // e.g. 'image/jpg'
    };
    formdata.append('user_photo', file);

这对你有帮助吗