Android 如何使用react native和react native drive api包装器将图像上载到google drive?

Android 如何使用react native和react native drive api包装器将图像上载到google drive?,android,react-native,google-drive-api,multipartform-data,image-uploading,Android,React Native,Google Drive Api,Multipartform Data,Image Uploading,我不熟悉react-native,并在react-native中使用react-native驱动器api包装器与google驱动器一起工作。因此,我能够创建文件夹,也能够创建一个新的文件与一些内容使用这个 const contents = "My text file contents"; GDrive.files.createFileMultipart( contents, "text/plain", { parents: ["root"],

我不熟悉react-native,并在react-native中使用react-native驱动器api包装器与google驱动器一起工作。因此,我能够创建文件夹,也能够创建一个新的文件与一些内容使用这个

  const contents = "My text file contents";
  GDrive.files.createFileMultipart(
       contents,
       "text/plain", {
         parents: ["root"],
         name: "text2.txt"
       },
       false);
但我不知道如何将设备中的文件上传到谷歌硬盘。最后,我的目标是上传图像和视频到硬盘。请帮我继续。你试过使用吗

您可以使用它获取图像,然后将数据发送到google drive


我可以用base64将图像上传到google drive,下面是示例代码

fs.readFile("file:///storage/emulated/0/DCIM/Camera/IMG_20190325_111404.jpg",'base64')
   .then((res => {             //conversion of image to base64
       console.log(res);
       GDrive.files.createFileMultipart(
            res,
            "'image/jpg'", {
            parents: ["root"], //or any path
            name: "photo.jpg"
          },
            true)              //make it true because you are passing base64 string otherwise the uploaded file will be not supported
             .then(a=>{
            console.log(a);
          });
        }
        );

respone.data和类型实际应包含的内容。你能在那里放一些示例行吗?注释响应。数据是base64编码的图像数据(仅限照片)。而response.type是图像的mime。。。你可以检查,但是如果文件太大,android应用程序会因为内存分配错误而崩溃。
fs.readFile("file:///storage/emulated/0/DCIM/Camera/IMG_20190325_111404.jpg",'base64')
   .then((res => {             //conversion of image to base64
       console.log(res);
       GDrive.files.createFileMultipart(
            res,
            "'image/jpg'", {
            parents: ["root"], //or any path
            name: "photo.jpg"
          },
            true)              //make it true because you are passing base64 string otherwise the uploaded file will be not supported
             .then(a=>{
            console.log(a);
          });
        }
        );