Use react-native-fs instead
This commit is contained in:
@@ -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<TCacheShape> {
|
||||
|
||||
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<string> {
|
||||
|
Reference in New Issue
Block a user