Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32375046
D9152.1765327910.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D9152.1765327910.diff
View Options
diff --git a/native/input/input-state-container.react.js b/native/input/input-state-container.react.js
--- a/native/input/input-state-container.react.js
+++ b/native/input/input-state-container.react.js
@@ -1,9 +1,9 @@
// @flow
+import * as FileSystem from 'expo-file-system';
import invariant from 'invariant';
import * as React from 'react';
import { Platform } from 'react-native';
-import * as Upload from 'react-native-background-upload';
import { useDispatch } from 'react-redux';
import { createSelector } from 'reselect';
import * as uuid from 'uuid';
@@ -1210,38 +1210,34 @@
}
const uploadEndpoint = blobService.httpEndpoints.UPLOAD_BLOB;
const { method } = uploadEndpoint;
- const uploadID = await Upload.startUpload({
- url: makeBlobServiceEndpointURL(uploadEndpoint),
- method,
+ const uploadTask = FileSystem.createUploadTask(
+ makeBlobServiceEndpointURL(uploadEndpoint),
path,
- type: 'multipart',
- field: 'blob_data',
- parameters: {
- blob_hash: blobHash,
+ {
+ uploadType: FileSystem.FileSystemUploadType.MULTIPART,
+ fieldName: 'blob_data',
+ httpMethod: method,
+ parameters: { blob_hash: blobHash },
},
- });
+ uploadProgress => {
+ if (options && options.onProgress) {
+ const { totalByteSent, totalBytesExpectedToSend } = uploadProgress;
+ options.onProgress(totalByteSent / totalBytesExpectedToSend);
+ }
+ },
+ );
if (options && options.abortHandler) {
- options.abortHandler(() => {
- Upload.cancelUpload(uploadID);
- });
+ options.abortHandler(() => uploadTask.cancelAsync());
+ }
+ try {
+ await uploadTask.uploadAsync();
+ } catch (e) {
+ throw new Error(
+ `Failed to upload blob: ${
+ getMessageForException(e) ?? 'unknown error'
+ }`,
+ );
}
- await new Promise((resolve, reject) => {
- Upload.addListener('error', uploadID, data => {
- reject(data.error);
- });
- Upload.addListener('cancelled', uploadID, () => {
- reject(new Error('request aborted'));
- });
- Upload.addListener('completed', uploadID, data => {
- resolve(data);
- });
- if (options && options.onProgress) {
- const { onProgress } = options;
- Upload.addListener('progress', uploadID, data =>
- onProgress(data.progress / 100),
- );
- }
- });
}
// 3. Send upload metadata to the keyserver, return response
@@ -1311,42 +1307,37 @@
path = resolvedPath;
}
}
- const uploadID = await Upload.startUpload({
+ const uploadTask = FileSystem.createUploadTask(
url,
path,
- type: 'multipart',
- headers: {
- Accept: 'application/json',
+ {
+ uploadType: FileSystem.FileSystemUploadType.MULTIPART,
+ fieldName: 'multimedia',
+ headers: {
+ Accept: 'application/json',
+ },
+ parameters,
},
- field: 'multimedia',
- parameters,
- });
+ uploadProgress => {
+ if (options && options.onProgress) {
+ const { totalByteSent, totalBytesExpectedToSend } = uploadProgress;
+ options.onProgress(totalByteSent / totalBytesExpectedToSend);
+ }
+ },
+ );
if (options && options.abortHandler) {
- options.abortHandler(() => {
- Upload.cancelUpload(uploadID);
- });
+ options.abortHandler(() => uploadTask.cancelAsync());
+ }
+ try {
+ const response = await uploadTask.uploadAsync();
+ return JSON.parse(response.body);
+ } catch (e) {
+ throw new Error(
+ `Failed to upload blob: ${
+ getMessageForException(e) ?? 'unknown error'
+ }`,
+ );
}
- return await new Promise((resolve, reject) => {
- Upload.addListener('error', uploadID, data => {
- reject(data.error);
- });
- Upload.addListener('cancelled', uploadID, () => {
- reject(new Error('request aborted'));
- });
- Upload.addListener('completed', uploadID, data => {
- try {
- resolve(JSON.parse(data.responseBody));
- } catch (e) {
- reject(e);
- }
- });
- if (options && options.onProgress) {
- const { onProgress } = options;
- Upload.addListener('progress', uploadID, data =>
- onProgress(data.progress / 100),
- );
- }
- });
};
handleUploadFailure(localMessageID: string, localUploadID: string) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 12:51 AM (11 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5859376
Default Alt Text
D9152.1765327910.diff (4 KB)
Attached To
Mode
D9152: [native] Use expo-file-system uploads
Attached
Detach File
Event Timeline
Log In to Comment