From f44a1597c0b40d56f0191f08fee423da8166c58a Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sun, 4 Feb 2024 23:58:07 -0700 Subject: [PATCH] Use react-native-fs instead --- component/video/camera.tsx | 37 ++++++++++++++++++++++--------------- package.json | 6 ++++-- yarn.lock | 22 ++++++++++++++++++---- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/component/video/camera.tsx b/component/video/camera.tsx index ec60cbe..3f63050 100644 --- a/component/video/camera.tsx +++ b/component/video/camera.tsx @@ -3,10 +3,7 @@ import { useIsFocused } from "@react-navigation/native"; import * as gql from "railbird-gql"; import React, { useCallback, useEffect, useRef, useState } from "react"; import { Button, StyleSheet, Text, View } from "react-native"; -import Upload, { - CompletedData, - ErrorData, -} from "react-native-background-upload"; +import * as RNFS from "react-native-fs"; import { Camera, CameraRuntimeError, @@ -40,19 +37,29 @@ class StreamUploadManager { async uploadChunk({ filepath, index }: { filepath: string; index: number }) { const uploadUrl = await this.getUploadLink(index); - const uploadId = await Upload.startUpload({ - url: uploadUrl, - path: filepath, + const uploadRequest = RNFS.uploadFiles({ + toUrl: uploadUrl, + files: [{ filepath: filepath }], method: "PUT", - }).catch((err) => console.log("Upload error!", err)); - // @ts-ignore - Upload.addListener("error", uploadId, (data: ErrorData) => { - console.log(`Error on: ${data}% ${index}%`); - }); - // @ts-ignore - Upload.addListener("completed", uploadId, (data: CompletedData) => { - console.log(`Chunk ${index} completed ${JSON.stringify(data)}`); + headers: { + "Content-Type": "application/octet-stream", + }, + begin: (res) => { + console.log("Start upload", res); + }, + progress: (res) => { + console.log("Uploading", res); + }, }); + console.log(JSON.stringify(uploadRequest)); + const result = await uploadRequest.promise.catch((err) => + console.log("Upload error!", err), + ); + if (response.statusCode == 200) { + console.log(`${filepath} Uploaded`); + } else { + console.log("SERVER ERROR"); + } } async getUploadLink(chunkId: number): Promise { diff --git a/package.json b/package.json index c94acbc..f245095 100644 --- a/package.json +++ b/package.json @@ -49,9 +49,9 @@ "railbird-gql": "git+https://dev.railbird.ai/railbird/railbird-gql.git#db82f66c5d3600d90f09c813f71287e176dc078b", "react": "18.2.0", "react-native": "0.72.6", - "react-native-background-upload": "git+https://github.com/kashaudhan/react-native-background-upload#c2b5105119242b3ab612ec2b485d510533bb6a37", "react-native-dotenv": "^3.4.9", "react-native-dropdown-picker": "^5.4.6", + "react-native-fs": "^2.20.0", "react-native-reanimated": "^3.6.2", "react-native-safe-area-context": "^4.8.2", "react-native-screens": "~3.22.0", @@ -75,7 +75,9 @@ }, "private": true, "prettier": { - "plugins": ["prettier-plugin-organize-imports"] + "plugins": [ + "prettier-plugin-organize-imports" + ] }, "resolutions": { "@babel/core": "^7.20.2", diff --git a/yarn.lock b/yarn.lock index fd054c5..903653a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4146,6 +4146,11 @@ balanced-match@^1.0.0: resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" integrity sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw== +base-64@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb" + integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA== + base64-js@^1.1.2, base64-js@^1.2.3, base64-js@^1.3.1, base64-js@^1.5.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" @@ -9717,10 +9722,6 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -"react-native-background-upload@git+https://github.com/kashaudhan/react-native-background-upload#c2b5105119242b3ab612ec2b485d510533bb6a37": - version "6.6.0" - resolved "git+https://github.com/kashaudhan/react-native-background-upload#c2b5105119242b3ab612ec2b485d510533bb6a37" - react-native-dotenv@^3.4.9: version "3.4.9" resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-3.4.9.tgz#621c5b0c1d0c5c7f569bfe5a1d804bec7885c010" @@ -9733,6 +9734,14 @@ react-native-dropdown-picker@^5.4.6: resolved "https://registry.yarnpkg.com/react-native-dropdown-picker/-/react-native-dropdown-picker-5.4.6.tgz#3736fc468de4a295e4df8d1f65ed2eadaf9b445f" integrity sha512-T1XBHbE++M6aRU3wFYw3MvcOuabhWZ29RK/Ivdls2r1ZkZ62iEBZknLUPeVLMX3x6iUxj4Zgr3X2DGlEGXeHsA== +react-native-fs@^2.20.0: + version "2.20.0" + resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.20.0.tgz#05a9362b473bfc0910772c0acbb73a78dbc810f6" + integrity sha512-VkTBzs7fIDUiy/XajOSNk0XazFE9l+QlMAce7lGuebZcag5CnjszB+u4BdqzwaQOdcYb5wsJIsqq4kxInIRpJQ== + dependencies: + base-64 "^0.1.0" + utf8 "^3.0.0" + react-native-reanimated@^3.6.2: version "3.6.2" resolved "https://registry.yarnpkg.com/react-native-reanimated/-/react-native-reanimated-3.6.2.tgz#8a48c37251cbd3b665a659444fa9778f5b510356" @@ -11398,6 +11407,11 @@ use-sync-external-store@^1.0.0: resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.2.0.tgz#7dbefd6ef3fe4e767a0cf5d7287aacfb5846928a" integrity sha512-eEgnFxGQ1Ife9bzYs6VLi8/4X6CObHMw9Qr9tPY43iKwsPw8xE8+EFsf/2cFZ5S3esXgpWgtSCtLNS41F+sKPA== +utf8@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1" + integrity sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ== + util-deprecate@^1.0.1, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf"